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 end = DateTime.now().add(timeout);
while (!end.isBefore(DateTime.now())) {
if (await condition()) {
return;
}
await Future.delayed(delay);
}
throw timeoutMessage;
}