initializer_for_non_existent_field
'{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;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.