dependOnInheritedWidgetOfExactType called before initState completed Flutter / Dart Origin: On your device OSI layer 7 · Application Last updated 4 Nov 2026

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.

Exact message you may see 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
Seen on: Flutter

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

  1. Move the call to didChangeDependencies()
  2. Use listen: false / context.read in initState
  3. Schedule with a post-frame callback

Detailed fix by platform

Flutter

  1. @override void didChangeDependencies() { super.didChangeDependencies(); final theme = Theme.of(context); }

How to diagnose

  1. Call — In initState?
  2. Needs — Subscription or one-time read?
  3. 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:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

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 (Flutter / Dart)A Ticker was active w…Android license status unknown / licenses not accepted — flutter doctor: Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses (Flutter / Dart)Android license statu…BadTokenException — WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? (Android)BadTokenExceptionBoxConstraints forces an infinite width — Flutter: BoxConstraints forces an infinite width. These invalid constraints were provided to RenderStack's layout() function (TextField in a Row) (Flutter / Dart)BoxConstraints forces…Can not perform this action after onSaveInstanceState — IllegalStateException: Can not perform this action after onSaveInstanceState (fragment transaction) (Android)Can not perform this …Dependency requires compileSdk 34 or later — Android Gradle: Execution failed for task ':app:checkDebugAarMetadata'. Dependency requires libraries and applications that depend on it to compile against version 34 or later of the Android APIs (Flutter / Dart)Dependency requires c…Error: Could not find the correct Provider — Flutter: Error: Could not find the correct Provider<CartModel> above this Consumer<CartModel> Widget (Flutter / Dart)Error: Could not find…Fragment not attached to a context — IllegalStateException: Fragment x not attached to a context / not attached to an activity (Android)Fragment not attached…dependOnI…

Explore the map of this error Full error map →

🧠 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.