Skip to main content

avoid-initializing-in-on-mount

added in: 1.6.0
Pro+

Warns when a late final variable is being initialized in the Component's onMount method.

Since a Component might be removed and added again, attempt to reinitialize a late final variable will result in runtime exception.

Example

❌ Bad:

class MyComponent extends Component {
late final int x;


void onMount() {
x = 1; // LINT: Avoid initializing final late variables in 'onMount'.
}
}

✅ Good:

class MyComponent extends Component {
int x;


void onMount() {
x = 1;
}
}