pumpWidget method
- Widget widget, {
- Duration? duration,
- EnginePhase phase = EnginePhase.sendSemanticsUpdate,
- bool wrapWithView = true,
Renders the UI from the given widget
.
Calls runApp with the given widget, then triggers a frame and flushes
microtasks, by calling pump with the same duration
(if any). The
supplied EnginePhase is the final phase reached during the pump pass; if
not supplied, the whole pass is executed.
Subsequent calls to this is different from pump in that it forces a full
rebuild of the tree, even if widget
is the same as the previous call.
pump will only rebuild the widgets that have changed.
This method should not be used as the first parameter to an expect or expectLater call to test that a widget throws an exception. Instead, use TestWidgetsFlutterBinding.takeException.
testWidgets('MyWidget asserts invalid bounds', (WidgetTester tester) async {
await tester.pumpWidget(const MyWidget());
expect(tester.takeException(), isAssertionError); // or isNull, as appropriate.
});
By default, the provided widget
is rendered into WidgetTester.view,
whose properties tests can modify to simulate different scenarios (e.g.
running on a large/small screen). Tests that want to control the
FlutterView into which content is rendered can set wrapWithView
to
false and use View widgets in the provided widget
tree to specify the
desired FlutterViews.
See also LiveTestWidgetsFlutterBindingFramePolicy, which affects how
this method works when the test is run with flutter run
.
Implementation
Future<void> pumpWidget(
Widget widget, {
Duration? duration,
EnginePhase phase = EnginePhase.sendSemanticsUpdate,
bool wrapWithView = true,
}) {
return TestAsyncUtils.guard<void>(() {
binding.attachRootWidget(wrapWithView ? binding.wrapWithDefaultView(widget) : widget);
binding.scheduleFrame();
return binding.pump(duration, phase);
});
}