Skip to main content

avoid-inherited-widget-in-initstate

added in: 1.4.0

Warns when context.dependOnInheritedWidgetOfExactType is transitively called from any invocation in initState.

Example

❌ Bad:

class _MyHomePageState<T> extends State<MyHomePage> {
int _counter = 0;


void initState() {
super.initState();

Theme.of(context); // LINT
}
}

✅ Good:

class _MyHomePageState<T> extends State<MyHomePage> {
int _counter = 0;


void initState() {
super.initState();
}
}