I am trying to stream data fetched from Firestore, but it's returned an empty list. The structure of the database look like this:
collection('users').doc().collection('products').doc()
I had successful return data throw this code:
Stream<List<ProductsModel>> getProductsList(uId) async* {
return usersRef.doc(uId).collection('products').snapshots().map(
(QuerySnapshot querySnapShot) => querySnapShot.docs
.map((DocumentSnapshot documentSnapshot) =>
ProductsModel.fromDoc(documentSnapshot))
.toList());
}
But when I am trying to this way it return an empty list:
Stream<List<ProductsModel>> getProductsList(uId) async* {
final userData = await usersRef.doc(uId).get();
String masterId = userData.get('masterId');
final event = usersRef
.doc(masterId)
.collection('products')
.snapshots()
.map((snapshot) {
return snapshot.docs.map((doc) => ProductsModel.fromDoc(doc)).toList();
});
yield* event;
}
Where is the problem in my code?
There is no error in my code. The mistake is in my database so masterId is return an emty Id.