Skip to content

Extract method refactors widget with async callback incorrectly #4053

@omarelb

Description

@omarelb

Describe the bug
In a build function, when calling extract method on a widget such as a button with an asynchronous callback (e.g. async onPressed method), the newly created method itself is marked as an async function, which is incorrect (at least in all the cases that I've used it). While the callback is asynchronous, the function that is returning the widget should not be.

To Reproduce
Steps to reproduce the behavior:

  1. Create a widget such as a button with an asynchronous callback. For example:
ListTile(
  title: "Hi",
  suffixIcon: IconButton(
    onPressed: () async {
       await asyncFunction()
    },
    icon: Icon(Icons.arrow_forward),
  )
)
  1. Place your cursor on IconButton, bring up the context menu, press extract method, and name the new function.

  2. The IconButton will have been replaced by your new method, but it has an await keyword before it that should not be there.

Expected behavior
The new function is added in place of the IconButton without an await in front of the function call. The new function does not return a Future<Widget> but just a Widget. The new method is not an async method.

Please complete the following information:

  • Operating System and version: macOS Monterey 12.2, M1 Chip
  • VS Code version: 1.68.1
  • Dart extension version: v3.44.0
  • Dart/Flutter SDK version: Flutter 2.10.4, Dart 2.16.2

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 bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions