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:
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:
Future<int> f() async {
late var v = 42;
return v;
}
If the initializer can't be rewritten, then remove the late modifier:
Future<int> f() async {
var v = await 42;
return v;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.