setState() called after dispose() Flutter / Dart Origin: On your device Last updated 15 Oct 2026

Flutter: setState() called after dispose(): _MyState#1a2b3 (lifecycle state: defunct, not mounted)

An async callback (network, timer, stream) finished after the widget was removed and then called setState.

Exact message you may see setState() called after dispose()lifecycle state: defunct, not mountedThis error happens if you call setState() on a State object for a widget that no longer appears in the widget tree
Seen on: Flutter

Meaning

Await the future, then check mounted before setState; cancel timers, animations and stream subscriptions in dispose().

Common causes

  • Future completes after navigating away
  • Timer/StreamSubscription not cancelled in dispose
  • AnimationController not disposed

⚡ Quick fix

  1. if (!mounted) return; before setState
  2. Cancel subscriptions/timers in dispose()
  3. Move async state to a state-management solution

Detailed fix by platform

Dart

  1. dart
    Future<void> load() async {
      final data = await api.fetch();
      if (!mounted) return;
      setState(() => items = data);
    }

How to diagnose

  1. Callback — Which async task?
  2. Dispose — Subscriptions cancelled?

🔧 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):

409 — HTTP 409 Conflict (HTTP)409A RenderFlex overflowed — Flutter: A RenderFlex overflowed by x pixels on the right/bottom (Flutter / Dart)A RenderFlex overflow…Actions must be plain objects — Error: Actions must be plain objects. Instead, the actual type was: 'function'. (React)Actions must be plain…BadTokenException — WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? (Android)BadTokenExceptionCan not perform this action after onSaveInstanceState — IllegalStateException: Can not perform this action after onSaveInstanceState (fragment transaction) (Android)Can not perform this …Error acquiring the state lock — Terraform: Error: Error acquiring the state lock — ConditionalCheckFailedException / state blob is already locked (Terraform)Error acquiring the s…Fragment not attached to a context — IllegalStateException: Fragment x not attached to a context / not attached to an activity (Android)Fragment not attached…IllegalStateException — java.lang.IllegalStateException (Java)IllegalStateExceptionsetState(…

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.