-
Notifications
You must be signed in to change notification settings - Fork 340
Description
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:
- 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),
)
)-
Place your cursor on
IconButton, bring up the context menu, pressextract method, and name the new function. -
The
IconButtonwill have been replaced by your new method, but it has anawaitkeyword 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