field_initialized_by_multiple_initializers
The field '{0}' can't be initialized twice in the same constructor.
Description
#The analyzer produces this diagnostic when the initializer list of a constructor initializes a field more than once. There is no value to allow both initializers because only the last value is preserved.
Example
#The following code produces this diagnostic because the field f
is being initialized twice:
dart
class C {
int f;
C() : f = 0, f = 1;
}
Common fixes
#Remove one of the initializers:
dart
class C {
int f;
C() : f = 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.