Skip to content

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

@lukehutch

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):

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