A Timer is still pending even after the widget tree was disposed Flutter / Dart Origin: On your device Last updated 4 Nov 2026

Flutter test: A Timer is still pending even after the widget tree was disposed

A widget test finished while a Timer or delayed Future was still scheduled.

Exact message you may see A Timer is still pending even after the widget tree was disposedTimer is still pending after widget tree disposedpumpAndSettle timed outA Timer is still pending even after the widget tree was disposed. Test failed
Seen on: Flutter

Meaning

Flutter tests fail if timers outlive the test. Cancel timers in dispose(), advance fake time with await tester.pump(duration) or pumpAndSettle, and avoid real delays. Libraries with periodic timers (animations, polling) need a mock or dispose.

Common causes

  • Timer/Future.delayed not cancelled in dispose()
  • Test ended before the timer fired
  • Periodic polling or retry timers
  • Animation looping forever (pumpAndSettle timeout)
  • Third-party plugin timers

⚡ Quick fix

  1. Cancel timers in dispose()
  2. Advance time: await tester.pump(const Duration(seconds: 2));
  3. Mock the timer-owning service in tests

Detailed fix by platform

Flutter

  1. In tests, replace delays with FakeAsync or inject a short duration

How to diagnose

  1. Timer — Where created?
  2. Dispose — Cancelled?
  3. Test — Time advanced?

🔧 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…BoxConstraints 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…Cleartext HTTP traffic not permitted — Flutter (Android): java.io.IOException: Cleartext HTTP traffic to api.example.com not permitted (Flutter / Dart)Cleartext HTTP traffi…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…Expected: exactly one matching candidate, Actual: found 0 widgets — Flutter test: Expected: exactly one matching candidate Actual: _TextFinder:<Found 0 widgets with text "Hello"> (Flutter / Dart)Expected: exactly one…setState() called after dispose() — Flutter: setState() called after dispose(): _MyState#1a2b3 (lifecycle state: defunct, not mounted) (Flutter / Dart)setState() called aft…A Timer i…

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.