Skip to main content

avoid-inherited-widget-in-initstate

added in: 1.4.0
Pro+

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: Avoid 'dependOnInheritedWidgetOfExactType' subscriptions in 'initState'.
}
}

✅ Good:

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


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