prefer_initializing_formals
Use an initializing formal to assign a parameter to a field.
Description
#The analyzer produces this diagnostic when a constructor parameter is used to initialize a field without modification.
Example
#The following code produces this diagnostic because the parameter c
is only used to set the field c
:
dart
class C {
int c;
C(int c) : this.c = c;
}
Common fixes
#Use an initializing formal parameter to initialize the field:
dart
class C {
int c;
C(this.c);
}
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.