You can use the Stream method firstWhere
to create a future that resolves when your Stream emits a true
value.
Future<bool> whenTrue(Stream<bool> source) {
return source.firstWhere((bool item) => item);
}
An alternative implementation without the stream method could use the await for
syntax on the Stream.
Future<bool> whenTrue(Stream<bool> source) async {
await for (bool value in source) {
if (value) {
return value;
}
}
// stream exited without a true value, maybe return an exception.
}