definitely_ unassigned_ late_ local_ variable
Details about the 'definitely_unassigned_late_local_variable' diagnostic produced by the Dart analyzer.
The late local variable '{0}' is definitely unassigned at this point.
Description
#
The analyzer produces this diagnostic when definite assignmentDefinite assignmentThe determination of whether a variable has definitely been
assigned a value before it's used. Learn more
analysis
shows that a local variable that's marked as late is read before being
assigned.
Example
#
The following code produces this diagnostic because x wasn't assigned a
value before being read:
void f(bool b) {
late int x;
print(x);
}
Common fixes
#Assign a value to the variable before reading from it:
void f(bool b) {
late int x;
x = b ? 1 : 0;
print(x);
}
Unless stated otherwise, the documentation on this site reflects Dart 3.10.3. Report an issue.