Skip to main content

prefer-initializing-in-declaration

effort: 2m
dart 3.13+
has IDE fix
has auto-fix
pro+

Suggests moving the constructor field initializer to the field declaration.

Example​

❌ Bad:

class Super(final String _first) {
final String val;

// LINT: This field should be initialized in its declaration.
// Try initializing the field where it is declared.
this : val = _first;
}

✅ Good:

class Super(final String _first) {
final val = _first;
}