await_ only_ futures
Details about the 'await_only_futures' diagnostic produced by the Dart analyzer.
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:
void f() async {
await 23;
}
Common fixes
#Remove the await:
void f() async {
23;
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.