initializing_formal_for_non_existent_field
'{0}' isn't a field in the enclosing class.
Description
#The analyzer produces this diagnostic when an initializing formal parameter is found in a constructor in a class that doesn't declare the field being initialized. 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 field x
isn't
defined:
class C {
int? y;
C(this.x);
}
Common fixes
#If the field name was wrong, then change it to the name of an existing field:
class C {
int? y;
C(this.y);
}
If the field name is correct but hasn't yet been defined, then declare the field:
class C {
int? x;
int? y;
C(this.x);
}
If the parameter is needed but shouldn't initialize a field, then convert it to a normal parameter and use it:
class C {
int y;
C(int x) : y = x * 2;
}
If the parameter isn't needed, then remove it:
class C {
int? y;
C();
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。