我想组合两个 observables 并在每个值发生变化时获取这两个值。
根据https://pub.dartlang.org/documentation/rxdart/latest/rx/Observable/combineLatest2.html及其大理石图,这正是我想要的。
所以我有:
var observable = CombineLatestStream.combine2(_matchViewModel.lineUpPlayers, _matchViewModel.playerSelectedState, (lineUpPlayers, playerSelectedState) {
return [lineUpPlayers, playerSelectedState];
});
return Stack(children: <Widget>[
Align(
alignment: Alignment.topRight,
child: Padding(
padding: EdgeInsets.all(8.0),
child: _buildFormationSelector(match)
)),
StreamBuilder(stream: observable, builder: (context, snapshot) {
if(snapshot.data == null) {
return new CircularProgressIndicator();
} else {
Map<String, Player> lineUpPlayers = snapshot.data[0];
bool playerSelectedState = snapshot.data[1];
return Column(
mainAxisAlignment: MainAxisAlignment
.spaceEvenly,
children: _buildFormation(match, lineUpPlayers)
);
}
})
]);
问题是 snapshot.data 始终为空。
可观察对象(从 BehaviorSubject 创建以恢复插入流中的最后一个值)_matchViewModel.lineUpPlayers 和 _matchViewModel.playerSelectedState 正在其他 StreamBuilders 中使用,它们似乎工作正常。
这有什么问题??