I want to get some data from FireStore.
Here is my code so far:
void getProducts() async {
QuerySnapshot querySnapshot = await FirebaseFirestore.instance
.collection("users")
.doc(uid)
.collection('products')
.get();
final fields = querySnapshot.docs.map((doc) => doc.data()).toList();
for (var f in fields) {
print(f);
}
}
The output is the following:
I/flutter (14637): {name: Milk, stock: 10, id: 1049}
I/flutter (14637): {name: Bread, stock: 2, id: 51}
I want to save the stock and the id for each product. How can I do this?