avoid_void_async
Avoid async
functions that return void
.
This rule is available as of Dart 2.1.
This rule has a quick fix available.
Details
#DO mark async
functions as returning Future<void>
.
When declaring an async
method or function which does not return a value,
declare that it returns Future<void>
and not just void
.
BAD:
dart
void f() async {}
void f2() async => null;
GOOD:
dart
Future<void> f() async {}
Future<void> f2() async => null;
EXCEPTION:
An exception is made for top-level main
functions, where the Future
annotation can (and generally should) be dropped in favor of void
.
GOOD:
dart
Future<void> f() async {}
void main() async {
await f();
}
Usage
#To enable the avoid_void_async
rule,
add avoid_void_async
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- avoid_void_async
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。