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
:
void f() async {
await 23;
}
Common fixes
#Remove the await
:
void f() async {
23;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.