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');
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.