Skip to main content

unnecessary_await_in_return

Details about the 'unnecessary_await_in_return' diagnostic produced by the Dart analyzer.

Unnecessary 'await'.

Description

#

The analyzer produces this diagnostic when an async function or method returns an await expression and the static type of the awaited Future is a subtype of the declared return type.

The await is unnecessary because returning a Future from an async function already produces a Future that completes with the same result.

The analyzer doesn't report this diagnostic for await expressions inside a try block because removing the await changes how errors from the awaited Future are handled.

Example

#

The following code produces this diagnostic because the function f has a return type of Future<int> and returns an awaited Future whose static type is also Future<int>:

dart
Future<int> f(Future<int> future) async {
  return await future;
}

Common fixes

#

Remove the unnecessary await:

dart
Future<int> f(Future<int> future) async {
  return future;
}