Skip to main content

avoid-unassigned-late-fields

effort: 4m
starter+

Warns when a private late field is not assigned a value.

Using late fields that have not received a value will result in runtime exceptions and should be avoided.

Example

❌ Bad:

class Test {
late final field = 'string';

// LINT: This late field is never assigned a value within its declaration.
// Try assigning a value or removing the 'late' keyword.
late int _privateLate;
}

✅ Good:

class Test {
late final field; // Correct, public

late int _anotherField; // Correct, assigned

final String regular; // Correct, not late

Test(this.regular) : _anotherField = 1;
}

Additional Resources