await_only_futures
Uses 'await' on an instance of '{0}', which is not a subtype of 'Future'.
Description
#The analyzer produces this diagnostic when the expression after await
has any type other than Future<T>
, FutureOr<T>
, Future<T>?
,
FutureOr<T>?
or dynamic
.
An exception is made for the expression await null
because it is a
common way to introduce a microtask delay.
Unless the expression can produce a Future
, the await
is unnecessary
and can cause a reader to assume a level of asynchrony that doesn't exist.
Example
#The following code produces this diagnostic because the expression after
await
has the type int
:
dart
void f() async {
await 23;
}
Common fixes
#Remove the await
:
dart
void f() async {
23;
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。