Skip to main content

avoid-unnecessary-late-fields

effort: 2m
has auto-fix
teams+

Warns when a late final field declaration is assigned in all constructors.

The late keyword has no effect in such cases and can be simply removed.

Example

❌ Bad:

class SomeClass {
// LINT: This 'late' keyword is unnecessary since the field is assigned in all constructors.
// Try removing the keyword.
late final String clientId;

SomeClass({required this.clientId});
}

class SomeOtherClass {
// LINT: This 'late' keyword is unnecessary since the field is assigned in all constructors.
// Try removing the keyword.
late final int anotherField;

SomeOtherClass() : anotherField = 1;
}

✅ Good:

class SomeClass {
final String clientId;

SomeClass({required this.clientId});
}

class SomeOtherClass {
late final int anotherField;

SomeOtherClass();
}