final_initialized_in_declaration_and_constructor
'{0}' is final and was given a value when it was declared, so it can't be set to a new value.
Description
#The analyzer produces this diagnostic when a final field is initialized twice: once where it's declared and once by a constructor's parameter.
Example
#The following code produces this diagnostic because the field f
is initialized twice:
class C {
final int f = 0;
C(this.f);
}
Common fixes
#If the field should have the same value for all instances, then remove the initialization in the parameter list:
class C {
final int f = 0;
C();
}
If the field can have different values in different instances, then remove the initialization in the declaration:
class C {
final int f;
C(this.f);
}
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.