How to use StreamZip with StreamBuilder?
985
Stream<List<QuerySnapshot>> combineStream() {
return StreamZip([stream1, stream2]);
}
return StreamBuilder(
stream: combineStream(),
builder: (context, snapshot) {
List<DocumentSnapshot> documentSnapshot = [];
List<dynamic> querySnapshot = snapshot.data.toList();
querySnapshot.forEach((query) {
documentSnapshot.addAll(query.docs);
})
}
);
Your documentSnapshot now contains your combined streams
Author by
FlutterFirebase
Updated on December 26, 2022Comments
-
FlutterFirebase over 1 year
I have two stream
stream1 stream2
I can give one to
StreamBuilder
and it work. For example:return StreamBuilder( stream: stream1,
But when I combine with
StreamZip
it now give error:StreamZip combinedStream() { return StreamZip(stream1, stream2]); } return StreamBuilder( stream: combinedStream,
How I can combine
stream1
andstream2
and give toStreamBuilder
? -
FlutterFirebase over 3 yearsThanks for reply! I try this but it not update correct in UI. It only show one stream result. Maybe because it emit at wrong time?
-
FlutterFirebase over 3 yearsThanks for reply! Is not simpler way with StreamZip?
-
Chichebe over 3 yearsI'm making use of the StreamZip in the combineStream to zip the two streams together.
-
FlutterFirebase over 3 yearsThanks for reply! Why cannot just use StreamZip alone?
-
Chichebe over 3 yearsI've not tried it that way. The code snippet I posted is how I'm currently using it in my project, and it works for me.
-
Sergio over 3 yearsIt should emit from both streams. Maybe another stream doesn't emit due to some condition?
-
Kamlesh almost 3 yearsKindly share
steam1
andsteam2
data so that we can know how are you creatingstream1
andstream2
variables and what type of data passing tomerge
function. Thanks. Look forward to hear you.