Flutter: dependOnInheritedWidgetOfExactType<_InheritedTheme>() or dependOnInheritedElement() was called before _HomeState.initState() completed
Theme.of(context), MediaQuery.of(context) or Provider.of(context) was used in initState, where inherited widgets are not yet available.
dependOnInheritedWidgetOfExactType was called before initState() completeddependOnInheritedElement() was called before initState() completedwas called before _State.initState() completedWhen an inherited widget changes, for example if the value of Theme.of() changes, its dependent widgets are rebuilt Meaning
Inherited data may change, so Flutter disallows subscribing in initState. Move the read to didChangeDependencies() or build(). For a one-time read without subscribing use context.read / Provider.of(context, listen: false).
Common causes
- Theme.of / MediaQuery.of in initState
- Provider.of(context) with listen true in initState
- Localizations.of in initState
- Reading inherited widget in a constructor
- Using context in a field initialiser
⚡ Quick fix
- Move the call to
didChangeDependencies() - Use
listen: false/context.readin initState - Schedule with a post-frame callback
Detailed fix by platform
Flutter
@override void didChangeDependencies() { super.didChangeDependencies(); final theme = Theme.of(context); }
How to diagnose
- Call — In initState?
- Needs — Subscription or one-time read?
- Fix — didChangeDependencies?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- A Ticker was active when the State was disposed Flutter: _HomeState#abc(ticker active) was disposed with an active Ticker. State.dispose() implementations must call dispose() on all their AnimationControllers
- Android license status unknown / licenses not accepted flutter doctor: Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses
- BadTokenException WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
Most viewed in Flutter / Dart
- A RenderFlex overflowed Flutter: A RenderFlex overflowed by x pixels on the right/bottom
- Null check operator used on a null value Dart/Flutter: Null check operator used on a null value
- SocketException: Failed host lookup Flutter: Unhandled Exception: SocketException: Failed host lookup: 'api.example.com' (OS Error: No address associated with hostname, errno = 7)
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026