pumpFrames method

Future<void> pumpFrames(
  1. Widget target,
  2. Duration maxDuration,
  3. [Duration interval = const Duration(milliseconds: 16, microseconds: 683)]
)

Repeatedly pump frames that render the target widget with a fixed time interval as many as maxDuration allows.

The maxDuration argument is required. The interval argument defaults to 16.683 milliseconds (59.94 FPS).

Implementation

Future<void> pumpFrames(
  Widget target,
  Duration maxDuration, [
  Duration interval = const Duration(milliseconds: 16, microseconds: 683),
]) {
  // The interval following the last frame doesn't have to be within the fullDuration.
  Duration elapsed = Duration.zero;
  return TestAsyncUtils.guard<void>(() async {
    binding.attachRootWidget(binding.wrapWithDefaultView(target));
    binding.scheduleFrame();
    while (elapsed < maxDuration) {
      await binding.pump(interval);
      elapsed += interval;
    }
  });
}