read_potentially_unassigned_final
The final variable '{0}' can't be read because it's potentially unassigned at this point.
Description
#The analyzer produces this diagnostic when a final local variable that isn't initialized at the declaration site is read at a point where the compiler can't prove that the variable is always initialized before it's referenced.
Example
#The following code produces this diagnostic because the final local
variable x
is read (on line 3) when it's possible that it hasn't yet
been initialized:
dart
int f() {
final int x;
return x;
}
Common fixes
#Ensure that the variable has been initialized before it's read:
dart
int f(bool b) {
final int x;
if (b) {
x = 0;
} else {
x = 1;
}
return x;
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。