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.
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 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
- Cancel timers in
dispose() - Advance time:
await tester.pump(const Duration(seconds: 2)); - Mock the timer-owning service in tests
Detailed fix by platform
Flutter
- In tests, replace delays with
FakeAsyncor inject a short duration
How to diagnose
- Timer — Where created?
- Dispose — Cancelled?
- 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:
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
- 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)
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
- Unsupported class file major version (Gradle / Java) Android Gradle: Execution failed — Unsupported class file major version 65 / Android Gradle plugin requires Java 17 to run
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