unnecessary_ async
Details about the 'unnecessary_async' diagnostic produced by the Dart analyzer.
Don't make a function 'async' if it doesn't use 'await'.
Description
#
The analyzer produces this diagnostic when a function, method, or
closure is marked async but doesn't contain any await expressions
or await for statements. The async modifier is unnecessary in these
cases and can be removed without changing the behavior of the code.
Example
#
The following code produces this diagnostic because the function f is
marked async but doesn't use await:
void f() async {
print('done');
}
Common fixes
#Remove the async modifier:
void f() {
print('done');
}
Unless stated otherwise, the documentation on this site reflects Dart 3.11.0. Report an issue.