Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract method refactors widget with async callback incorrectly #4053

Closed
omarelb opened this issue Jul 9, 2022 · 2 comments
Closed

Extract method refactors widget with async callback incorrectly #4053

omarelb opened this issue Jul 9, 2022 · 2 comments
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is bug
Milestone

Comments

@omarelb
Copy link

omarelb commented Jul 9, 2022

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
@omarelb omarelb added the is bug label Jul 9, 2022
@DanTup
Copy link
Member

DanTup commented Jul 11, 2022

Thanks, I can repro this. A smaller example without the Flutter dependency is:

void f() {
  g(() {
    return Future.value(null);
  });
  g(() async {
    await null;
  });
}

void g(Future<void> Function() func) {}

Extracting the first call to g is fine, but the second one gets the unwanted await.

@DanTup DanTup added this to the v3.46.0 milestone Jul 11, 2022
@DanTup DanTup added in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server labels Jul 11, 2022
copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue Jul 11, 2022
…ction expression is async

Fixes Dart-Code/Dart-Code#4053.

Change-Id: I13a76fab9a2e6f9e08bbd736f997b37bf07ae78d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/251100
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
@DanTup
Copy link
Member

DanTup commented Jul 11, 2022

Fixed by dart-lang/sdk@97fa3ca. The fix is in the Dart SDK, so will show up in a Future SDK release (and not a VS Code extension update).

@DanTup DanTup closed this as completed Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is bug
Projects
None yet
Development

No branches or pull requests

2 participants