async_ return_ with_ no_ await
Details about the 'async_return_with_no_await' diagnostic produced by the Dart analyzer.
Returning a 'Future' without 'await'.
Description
#
The analyzer produces this diagnostic when a
Future is returned from an
async function without using await.
Returning an unawaited Future from an
async function means any exception thrown by the
Future might not propagate as expected. Having
the exception thrown at the await site helps
identify the source of the exception and makes it easier to
debug.
Example
#
The following code produces this diagnostic because it returns
the Future from futureString without
using await:
Future<String> futureString(Future<String> value) async {
return value;
}
Common fixes
#
Add await before the returned
Future:
Future<String> futureString(Future<String> value) async {
return await value;
}
If you don't need to use await, then remove
async from the function body:
Future<String> futureString(Future<String> value) {
return value;
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.