prefer-initializing-formals
Suggests using initializing formal parameters when applicable.
Example
❌ Bad:
class Some {
final String value;
final String another;
const Some(String val, {required String named})
// LINT: Use an initializing formal to assign a parameter to a field.
// Try using 'this.value' to initialize the field.
: value = val,
another = named;
}
class Another {
final String _val;
// LINT: Use an initializing formal to assign a parameter to a field.
// Try using 'this.value' to initialize the field.
const Another(String _value) : _val = _value;
}
✅ Good:
class Some {
final String value;
final String another;
const Some(this.value, {required String named}) : another = named;
}
class Another {
final String _val;
const Another(this._value);
}