whenValueNonNull<T> function
Implementation
Future<T> whenValueNonNull<T>(
ValueListenable<T> listenable, {
Duration? timeout,
}) {
if (listenable.value != null) return Future.value(listenable.value);
final completer = Completer<T>();
void listener() {
final value = listenable.value;
if (value != null) {
completer.complete(value);
listenable.removeListener(listener);
}
}
listenable.addListener(listener);
if (timeout != null) {
return completer.future.timeout(timeout);
}
return completer.future;
}