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;
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.