async
async copied to clipboard
Updating UI based on StreamGroup.merge(streams).asBroadcastStream()
Hi!
Firstly thank you so much for this package. I've been using it quite a lot recently and it's very nice!
I don't think this is a bug, rather a question. I'm subscribing to a single StreamSubscription that listens to changes in a QuerySnapshot. My problem is, I'm combining two streams in this subscription using StreamGroup.merge and asBroadCastStream. When I do this, the changes in the StreamSubscription doesn't trigger.
Do you have any idea how I could solve this?
Any help would greatly be appreciated!
Cheers!
Below is my code for the Streams and the Subscription:
Combining Streams:
final List<Stream<QuerySnapshot>> streams = [];
var chunks = [];
for (var i = 0; i < teamUids.length; i += 10) {
chunks.add(teamUids.sublist(
i, i + 10 > teamUids.length ? teamUids.length : i + 10));
}
for (final List<String> chunk in chunks) {
final Stream<QuerySnapshot> qs = _firestore
.collection('liveGames')
.where('teamUids', arrayContainsAny: chunk)
.where('status', isEqualTo: 'live')
.snapshots();
streams.add(qs);
}
return StreamGroup.merge(streams).asBroadcastStream();
StreamSubscription:
_liveGamesStream =
userRepository.grabFavTeamsLiveGames(teamUids).listen((event) {
final List<LiveGameModel> games = state.liveGames
..addAll(liveGameListFromQuerySnapshot(event));
emit(state.copyWith(blocStatus: BlocStatus.initial, liveGames: games));
});