Skip to main content

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;
}