Stream 达斯:你如何让未来等待一条小溪?

Stream 达斯:你如何让未来等待一条小溪?,stream,dart,future,Stream,Dart,Future,我想等待一个梦想成真,然后从未来回来,但我似乎不能让我的未来等待溪流 Future<bool> ready() { return new Future<bool>(() { StreamSubscription readySub; _readyStream.listen((aBool) { if (aBool) { return true; } }); }); } Future<bool>

我想等待一个梦想成真,然后从未来回来,但我似乎不能让我的未来等待溪流

Future<bool> ready() {
  return new Future<bool>(() {
    StreamSubscription readySub;
    _readyStream.listen((aBool) {
      if (aBool) {
        return true;
      }
    });
  });
}
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.
}
Future ready(){
返回新的未来(){
StreamSubscription readySub;
_readyStream.listen((aBool){
if(aBool){
返回true;
}
});
});
}

您可以使用Stream方法创建一个未来,当您的流发出
true
值时,该未来将得到解决

Future<bool> whenTrue(Stream<bool> source) {
  return source.firstWhere((bool item) => item);
}

我们必须为它创建一个未来的建设者吗?