field_initializer_factory_constructor
Initializing formal parameters can't be used in factory constructors.
Description
#The analyzer produces this diagnostic when a factory constructor has an initializing formal parameter. Factory constructors can't assign values to fields because no instance is created; hence, there is no field to assign.
Example
#The following code produces this diagnostic because the factory constructor uses an initializing formal parameter:
dart
class C {
int? f;
factory C(this.f) => throw 0;
}
Common fixes
#Replace the initializing formal parameter with a normal parameter:
dart
class C {
int? f;
factory C(int f) => throw 0;
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。