import 'package:flutter_test/flutter_test.dart'; /// Waits until [condition] holds, checking every few milliseconds, and fails /// after [timeout]: for what follows a real timer, without betting on how /// fast a busy machine runs. Future eventually( bool Function() condition, { Duration timeout = const Duration(seconds: 10), }) async { final stopwatch = Stopwatch()..start(); while (!condition()) { if (stopwatch.elapsed > timeout) { fail('Still not so after $timeout.'); } await Future.delayed(const Duration(milliseconds: 10)); } }