late_ final_ local_ already_ assigned
Details about the 'late_final_local_already_assigned' diagnostic produced by the Dart analyzer.
The late final local variable is already assigned.
Description
#
The analyzer produces this diagnostic when the analyzer can
prove that a local variable marked as both
late and final was already assigned
a value at the point where another assignment occurs.
Because final variables can only be assigned
once, subsequent assignments are guaranteed to fail, so
they're flagged.
Example
#
The following code produces this diagnostic because the
final variable v is assigned a value
in two places:
int f() {
late final int v;
v = 0;
v += 1;
return v;
}
Common fixes
#
If you need to be able to reassign the variable, then remove
the final
keyword:
int f() {
late int v;
v = 0;
v += 1;
return v;
}
If you don't need to reassign the variable, then remove all except the first of the assignments:
int f() {
late final int v;
v = 0;
return v;
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.