prefer_async_await
Severity | Quick Fix | Options |
---|---|---|
Info | ❌ | ❌ |
Details
DO use async/await instead of using raw futures.
Using async/await improves code readability.
see: effective-dart
Bad
void fetchData() {
performAsyncOperation().then((result) {
print(result);
}).catchError((Object? error) {
print('Error: $error');
}).whenComplete(() {
print('Done');
});
}
Good
Future<void> fetchData() async {
try {
final result = await performAsyncOperation();
print(result);
} catch (error) {
print('Error: $error');
} finally {
print('Done');
}
}