final_not_initialized
Details about the 'final_not_initialized' diagnostic produced by the Dart analyzer.
The final variable '{0}' must be initialized.
Description
#The analyzer produces this diagnostic when a final field or variable isn't initialized.
Example
#
The following code produces this diagnostic because x doesn't have an
initializer:
final x;
Common fixes
#For variables and static fields, you can add an initializer:
final x = 0;
For instance fields, you can add an initializer as shown in the previous example, or you can initialize the field in every constructor. You can initialize the field by using an initializing formal parameter:
class C {
final int x;
C(this.x);
}
You can also initialize the field by using an initializer in the constructor:
class C {
final int x;
C(int y) : x = y * 2;
}
除非另有说明,文档之所提及适用于 Dart 3.10.3 版本报告页面问题.