unnecessary_async
No await no async.
Details
#Functions that don't do await
don't have to be async
.
Usually such functions also don't have to return a Future
, which allows an invoker to avoid await
in its code, etc. Synchronous code in general runs faster, and is easier to reason about.
BAD:
void f() async {
// await Future.delayed(const Duration(seconds: 2));
print(0);
}
GOOD:
void f() {
// await Future.delayed(const Duration(seconds: 2));
print(0);
}
Enable
#To enable the unnecessary_async
rule, add unnecessary_async
under linter > rules in your analysis_options.yaml
file:
linter:
rules:
- unnecessary_async
If you're instead using the YAML map syntax to configure linter rules, add unnecessary_async: true
under linter > rules:
linter:
rules:
unnecessary_async: true
Unless stated otherwise, the documentation on this site reflects Dart 3.6.2. Page last updated on 2025-01-27. View source or report an issue.