pump and settle
- Flutter course
- Advanced
- Lesson 63/69
- 4 min
Drive animated tests with pump and pumpAndSettle.
pump and pumpAndSettle
pump advances a single frame; pumpAndSettle advances frames until all animations and timers complete. When testing animated widgets, you advance time with pump(Duration) and then verify with expect.
await tester.pumpWidget(MyAnimatedWidget());
await tester.pump(const Duration(seconds: 1));
await tester.pumpAndSettle();
expect(find.text('Done'), findsOneWidget);pump with Duration
pump(Duration) triggers the frames within a given duration, letting you test intermediate animation states. pumpAndSettle advances in 100ms intervals until animations are done.
Practice Animated test
In main, write a testWidgets test named 'animasyon biter'. Render MaterialApp(home: Text('Bitti')) with pumpWidget. Call pumpAndSettle. Verify with find.text('Bitti') and findsOneWidget. Finally print 'test tanimlandi'.
Starter code
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
void main() {
// 'animasyon biter' adlı testWidgets testi yaz
// pumpWidget ile MaterialApp içinde Text render et
// pumpAndSettle ile animasyonların bitmesini bekle
// find.text ile metni bul ve findsOneWidget ile doğrula
// son olarak 'test tanimlandi' yazdir
}Sample solution
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
void main() {
testWidgets('animasyon biter', (tester) async {
await tester.pumpWidget(
const MaterialApp(home: Text('Bitti')),
);
await tester.pumpAndSettle();
expect(find.text('Bitti'), findsOneWidget);
});
print('test tanimlandi');
}Expected output
test tanimlandi
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does pumpAndSettle do?
- Renders the widget
- Advances until all animations and timers complete Correct answer
- Stops the test
- Advances one frame
Explanation: pumpAndSettle keeps advancing frames until there are no more changes; it waits for animations to finish.
2 pumpAndSettle call
await tester.____();
await tester.pumpAndSettle();
Explanation: tester.pumpAndSettle advances frames until all animations are done; pump advances only one frame or by a given Duration.
3 pump matches
| Term | Meaning |
|---|---|
pump |
Advances one frame |
pumpAndSettle |
Advances until animations complete |
Duration |
Time interval |
pumpWidget |
Initial render |