pumpMicrotasks method

Future<void> pumpMicrotasks([
  1. int rounds = 8
])

Lets already-scheduled microtasks and completed futures run, without moving time.

Deliberately microtasks only, never Future.delayed. Under testWidgets the binding fakes real Timers and only advances them when the tester pumps, so awaiting a zero-duration delay there deadlocks: the await blocks the test, and only the test could unblock it. Microtasks are not faked, so they drain in both zones.

Implementation

Future<void> pumpMicrotasks([int rounds = 8]) async {
  for (var i = 0; i < rounds; i++) {
    await Future<void>.microtask(() {});
  }
}