Skip to main content

avoid-late-final-reassignment

added in: 1.23.0
Pro+

Warns when a late final variable is assigned multiple times in the same block.

Assigning to a late final variables multiple times will throw at runtime and should be avoided.

Example

❌ Bad:

class _TestState {
late final String _title;

void initState() {
_title = 'title';
_title = 'another'; // LINT: This late final field is already assigned. Try removing the 'final' modifier or don't reassign the value.
}
}

✅ Good:

class _TestState {
late final String _title;

void initState() {
_title = 'title';
}
}