i have a problem with merged stream and StreamBuilder. im trying to merge multiple streams from firestore that each one represents a grocery list. my result should be a ListView that combines all list in a some group. from some reason,my StreamBuilder shows a single stream list in one tab but doesnt show it in another.
group list app photo personal list app photo
code:
Stream<QuerySnapshot<Map<String, dynamic>>> getPesonalStream<T>() {
final userGroceries =
_fireStore.collection("users").doc(email).collection("groceries");
return userGroceries.snapshots();
}
Stream<QuerySnapshot<Map<String, dynamic>>> getGroupStream<T>() {
List<Stream<QuerySnapshot<Map<String, dynamic>>>> list = [];
_fireStore
.collection("groups")
.doc(gid)
.snapshots()
.forEach(((docSnapshot) {
List<dynamic> members = docSnapshot.data()!["members"];
list = members
.map((member) => _fireStore
.collection("users")
.doc(member)
.collection("groceries")
.snapshots())
.toList();
}));
return CombineLatestStream(list,
(values) => values.last as QuerySnapshot<Map<String, dynamic>>)
.asBroadcastStream();
// return StreamGroup.merge(list).asBroadcastStream();
}
as you can see iv tried a few ways to combine my streams and non workes
body:
body: TabBarView(children: [
_buildContent(
context,
db.getGroupStream(),
),
_buildContent(
context,
db.getPesonalStream(),
),
]),
my builder:
Widget _buildContent(BuildContext context, Stream<QuerySnapshot> stream) {
return StreamBuilder<QuerySnapshot>(
stream: stream,
builder: (context, snapshot) {
if (snapshot.hasData) {
final docs = snapshot.data!.docs;
if (docs.isEmpty) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"The list is empty",
style: TextStyle(fontSize: 32, color: Colors.black54),
),
Text(
"Add a new item to get started",
style: TextStyle(fontSize: 16, color: Colors.black54),
),
],
));
}
int index = -1;
final cards = docs
.map((doc) => CrossableListTile(
doc, _showSetGroceryButtomSheetForm, index++))
.toList();
return Container(
padding: EdgeInsets.symmetric(vertical: 20, horizontal: 10),
child: ListView(
children: cards,
),
);
} else if (snapshot.hasError) {
return Center(
child: Column(
children: [Text("An error has occured while loading you'r list")],
),
);
}
return Center(
child: CircularProgressIndicator(
color: Colors.black,
));
},
);
}