What's the difference between tester.pump() and tester.pumpAndSettle()?
Short Answer
pump() advances the clock by one frame (or a given duration); pumpAndSettle() repeatedly pumps frames until there are no more scheduled frames, which is more convenient but can hang or time out if something schedules frames indefinitely.
After an action like tapping a button, Flutter doesn't rebuild synchronously — you need to pump() to process the resulting frame. For a single state update, one pump() is enough. For anything involving animation or a transition, you'd need many pumps to reach the final settled state — pumpAndSettle() automates that by looping pump() calls until no new frames are scheduled.
The catch: pumpAndSettle() will throw a timeout if something keeps scheduling frames indefinitely, such as an infinitely-repeating animation (a loading spinner) — in that case you must use explicit pump(duration) calls instead.
Common Mistakes
- ×Always reaching for pumpAndSettle() out of habit, then getting a confusing timeout on a screen with an infinite/repeating animation.
- ×Using a single pump() when a multi-step animation/transition genuinely needs multiple frames to reach its final state.