Skip to main content

avoid-late-context

added in: 1.4.0

Warns when the context is used inside a late field.

Using the context in late fields might result in an unexpected behavior due to late fields being initialized lazily.

Example

❌ Bad:

class _SomeState extends State<T> {
late final _myState = _create(context); // LINT
}

✅ Good:

class _SomeState extends State<T> {
late final _myState = _create();
}