discarded_futures
Don't invoke asynchronous functions in non-async
blocks.
This rule is available as of Dart 2.18.
This rule has a quick fix available.
Details
#Making asynchronous calls in non-async
functions is usually the sign of a
programming error. In general these functions should be marked async
and such
futures should likely be awaited (as enforced by unawaited_futures
).
DON'T invoke asynchronous functions in non-async
blocks.
BAD:
dart
void recreateDir(String path) {
deleteDir(path);
createDir(path);
}
Future<void> deleteDir(String path) async {}
Future<void> createDir(String path) async {}
GOOD:
dart
Future<void> recreateDir(String path) async {
await deleteDir(path);
await createDir(path);
}
Future<void> deleteDir(String path) async {}
Future<void> createDir(String path) async {}
Usage
#To enable the discarded_futures
rule,
add discarded_futures
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- discarded_futures
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。