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:
dart
void f() async {
// await Future.delayed(const Duration(seconds: 2));
print(0);
}
GOOD:
dart
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:
analysis_options.yaml
yaml
linter:
rules:
- unnecessary_async
If you're instead using the YAML map syntax to configure linter rules,
add unnecessary_async: true
under linter > rules:
analysis_options.yaml
yaml
linter:
rules:
unnecessary_async: true
除非另有说明,文档之所提及适用于 Dart 3.7.1 版本,本页面最后更新时间: 2025-01-27。 查看文档源码 或者 报告页面问题。