Skip to main content

avoid-unassigned-late-fields

added in: 1.6.0
Pro+
preset: recommended

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';

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; // LINT: This field is never assigned a value. Try assigning a value to it or removing the 'late' keyword.
}

✅ 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