initializer_for_non_existent_field
Details about the 'initializer_for_non_existent_field' diagnostic produced by the Dart analyzer.
'{0}' isn't a field in the enclosing class.
Description
#The analyzer produces this diagnostic when a constructor initializes a field that isn't declared in the class containing the constructor. Constructors can't initialize fields that aren't declared and fields that are inherited from superclasses.
Example
#
The following code produces this diagnostic because the initializer is
initializing x, but x isn't a field in the class:
class C {
int? y;
C() : x = 0;
}
Common fixes
#If a different field should be initialized, then change the name to the name of the field:
class C {
int? y;
C() : y = 0;
}
If the field must be declared, then add a declaration:
class C {
int? x;
int? y;
C() : x = 0;
}
除非另有说明,文档之所提及适用于 Dart 3.10.3 版本报告页面问题.