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>:
Future<int> f(Future<int> future) async {
return await future;
}
Common fixes
#Remove the unnecessary await:
Future<int> f(Future<int> future) async {
return future;
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.