Skip to content

"Convert to StatelessWidget" does not remove all instances of widget. #4621

Closed

Description

@lukehutch

Describe the bug

Before:

class ValueButton<T extends Enum> extends StatefulWidget {
  final String label;
  final T value;
  final void Function(T?) onChanged;

  const ValueButton(
      {required this.label,
      required this.value,
      required this.onChanged,
      super.key});

  @override
  State<ValueButton> createState() => _ValueButtonState();
}

class _ValueButtonState<T extends Enum> extends State<ValueButton<T>> {
  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
        onPressed: () => widget.onChanged(widget.value),
        child: Text(widget.label));
  }
}

After "Convert to StatelessWidget":

class ValueButton<T extends Enum> extends StatelessWidget {
  final String label;
  final T value;
  final void Function(T?) onChanged;

  const ValueButton(
      {required this.label,
      required this.value,
      required this.onChanged,
      super.key});

  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
        onPressed: () => widget.onChanged(value),    // ***** `widget.` was not removed from `onChanged`
        child: Text(label));
  }
}

widget.value and widget.label correctly had widget. removed, but widget.onChanged was not correctly changed to onChanged.

Please complete the following information:

  • Operating System and version: Linux fedora 6.3.6-200.fc38.x86_64
  • VS Code version: 1.79.2
  • Dart extension version: 3.66.0
  • Dart/Flutter SDK version: 3.0.5
  • Target device (if the issue relates to Flutter debugging):

Activity

  1. added this to the v3.70.0 milestone on Jul 3, 2023
  2. added
    in lsp/analysis serverSomething to be fixed in the Dart analysis server
    relies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available
    in editorRelates to code editing or language features
    on Jul 3, 2023
  3. DanTup commented on Jul 5, 2023

    @DanTup
    Member

    Fixed by dart-lang/sdk@0daf23e. The change is in the analysis server, so this will show up in a future SDK release.

  4. lukehutch commented on Jul 5, 2023

    @lukehutch
    Author

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresin lsp/analysis serverSomething to be fixed in the Dart analysis serveris bugrelies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions