Skip to main content

prefer-return-await

added in: 1.2.0
🛠
Pro+
preset: recommended

Warns when a Future is returned from a try / catch block without an await.

Not awaiting a Future leads to an error not being catch by the catch block.

Example

❌ Bad:

Future<String> report(Iterable<String> records) async {
try {
return anotherAsyncMethod(); // LINT
} catch(e) {
print(e);
}
}

✅ Good:

Future<String> report(Iterable<String> records) async {
try {
return await anotherAsyncMethod();
} catch(e) {
print(e);
}
}