Add @awaitNotRequired annotation to flutter sdk#181513
Conversation
|
Do we have a plan on the criteria that justify a |
There is a lint ( |
|
Thanks for the review @dkwingsmt. I didn't think there are situations in the framework where some Is this review exhaustive? i.e are the methods you've pointed out the only ones that should have |
|
I didn't review the ones under |
There was a problem hiding this comment.
Code Review
This pull request introduces the @awaitNotRequired annotation across the Flutter SDK to address unawaited_futures lint warnings. The changes are extensive, touching many files to annotate methods that return a Future but are not intended to be awaited, such as animation controllers, navigation methods, and platform channel invocations. This makes the code cleaner and the intent clearer. Additionally, the PR fixes a few instances in tests where tester.pump() was not correctly awaited. The changes are well-executed and improve the overall code quality by adhering to linting best practices.
|
Related: #182233 void A() {
assert(false); // Exception thrown
}
Future<void> animateTo() async {
A();
}
void handleEvent() { // Sync handler
animateTo(); // The future is not awaited.
}
void D() {
try {
handleEvent(); // D thought this was enough catching.
} catch {
FlutterError.report(...);
}
}This shows the risk of allowing futures to not be awaited: Async errors will not be caught at all. Therefore I think we should not allow futures to be un-awaited (except maybe in tests, with discretion). All futures should either be awaited or have a |
| _canceled = true; | ||
| } | ||
|
|
||
| @awaitNotRequired |
There was a problem hiding this comment.
I think we should keep the annotation here. This PR added it: #79163? WDYT @dkwingsmt
There was a problem hiding this comment.
Yeah, I think having no await is the intention here.
There was a problem hiding this comment.
or apply unawaited to the call site
Fixes flutter#184315 Part of flutter#181513 --------- Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
Fixes flutter#184315 Part of flutter#181513 --------- Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
PR: flutter#184042 Revert: flutter#184429 Fixes flutter#184315 Part of flutter#181513 --------- Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com>
Part of flutter#181513 --------- Co-authored-by: Tong Mu <dkwingsmt@users.noreply.github.com> Co-authored-by: Kate Lovett <katelovett@google.com>
|
This PR is affected by code freeze. I've suggested Victor to split this PR into two parts, landing the non-material/cupertino part while holding the remaining until the freeze is lifted. |
|
I moved the code-freezed changes to a separate PR. So this can be merged cleanly. |
chunhtai
left a comment
There was a problem hiding this comment.
LGTM, but for internal facing api, we should use unawaited at the call site
| _canceled = true; | ||
| } | ||
|
|
||
| @awaitNotRequired |
There was a problem hiding this comment.
or apply unawaited to the call site
Part of Use @awaitNotRequired in Flutter SDK
Turned on the
unawaited_futureslint and added the annotation to every function declared in the flutter SDK and flagged by the linter. This means the annotation is only added toFuture-returning functions called at least once without theawaitkeyword preceding it. So if there exists aFuture-returning function in the Flutter SDK that does not need to beawaited, but all call sites in the SDK have theawaitkeyword, it is not annotated.EDIT: Opened PRs to add
awaits orignores to callsites instead of adding the annotation. Some functions may still require this annotation, but this set is much smaller than originally anticipated.