I am playing with flutter but I ran into an issue with firestore that I can\'t figure out.
let\'s say I would like to retrieve the purchaser history of a customer and I
Short answer i didn't pay attention to how you use a future
Get the productId from the user table
Future<List<DocumentSnapshot>> getProduceID() async{
var data = await Firestore.instance.collection('users').document(widget.userId).collection('Products').getDocuments();
var productId = data.documents;
return productId;
}
Then call this using .then() rather than try to apply the returned data to the variable as that is not how a future it works
var products;
getProduceID().then((data){
for(int i = 0; i < s.length; i++) {
products = Firestore.instance.collection('products')
.document(data[i]['productID'])
.snapshots();
if (products != null) {
products.forEach((product) {
print(product.data.values);
});
}
}
});