avoid_ void_ async
Learn about the avoid_void_async linter rule.
Avoid async functions that return
void.
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:
void f() async {}
void f2() async => null;
GOOD:
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:
Future<void> f() async {}
void main() async {
await f();
}
Enable
#
To enable the avoid_void_async rule, add
avoid_void_async under
linter > rules in your
analysis_options.yaml
file:
linter:
rules:
- avoid_void_async
If you're instead using the YAML map syntax to configure
linter rules, add avoid_void_async: true under
linter > rules:
linter:
rules:
avoid_void_async: true
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.