await_in_late_local_variable_initializer
The 'await' expression can't be used in a 'late' local variable's initializer.
Description
#The analyzer produces this diagnostic when a local variable that has the late
modifier uses an await
expression in the initializer.
Example
#The following code produces this diagnostic because an await
expression is used in the initializer for v
, a local variable that is marked late
:
dart
Future<int> f() async {
late var v = await 42;
return v;
}
Common fixes
#If the initializer can be rewritten to not use await
, then rewrite it:
dart
Future<int> f() async {
late var v = 42;
return v;
}
If the initializer can't be rewritten, then remove the late
modifier:
dart
Future<int> f() async {
var v = await 42;
return v;
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.