Skip to main content

avoid-unassigned-late-fields

Warns when a 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 field is never assigned a value.
// Try assigning a value to it or removing the 'late' keyword.
late int uninitializedField;

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

✅ Good:

class Test {
late final field = 'string';

late int anotherField; // Correct, assigned

final String regular; // Correct, not late

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

Known Limitations

This rule checks assignments to late fields only in the declaration file.

Additional Resources