waitFor function
Implementation
Future<void> waitFor(
Future<bool> Function() condition, {
Duration timeout = const Duration(seconds: 10),
String timeoutMessage = 'condition not satisfied',
Duration delay = _shortDelay,
}) async {
final DateTime end = DateTime.now().add(timeout);
while (!end.isBefore(DateTime.now())) {
if (await condition()) {
return;
}
await Future.delayed(delay);
}
throw timeoutMessage;
}