await_only_futures
僅等待 Future。
詳細資訊
#避免在非 Future 的任何事物上使用 await。
Await 允許用於以下類型:Future<X>
、FutureOr<X>
、Future<X>?
、FutureOr<X>?
和 dynamic
。
此外,明確允許使用 await null
作為引入微任務延遲的方式。
不良範例
dart
main() async {
print(await 23);
}
良好範例
dart
main() async {
await null; // If a delay is really intended.
print(23);
}
啟用
#若要啟用 await_only_futures
規則,請在您的 analysis_options.yaml
檔案中的 linter > rules 下新增 await_only_futures
analysis_options.yaml
yaml
linter:
rules:
- await_only_futures
如果您改為使用 YAML 對應語法來設定 linter 規則,請在 linter > rules 下新增 await_only_futures: true
analysis_options.yaml
yaml
linter:
rules:
await_only_futures: true
除非另有說明,否則本網站上的文件反映的是 Dart 3.7.1。頁面上次更新於 2025-03-07。 查看原始碼 或 回報問題。