'The getter 'doc' isn't defined for the class 'QuerySnapshot<Object>'
I'm trying to create a food track app with bar scanning and I'm working with firebase_auth 3.3.12 and firestore. My code in the database.dart is:
List<Scan> _scanListFromSnapshot(QuerySnapshot snapshot) {
return snapshot.doc.map((doc){
return Scan(
productID: doc.documentID,
productName: doc.data['food_name'] ?? '',
productCalories: doc.data['calories'] ?? 0,
productCarbs: doc.data['carbohydrates'] ?? 0,
productFat: doc.data['fat'] ?? 0,
productProtein: doc.data['protein'] ?? 0,
dateTime: doc.data['date_time'] ?? null,
grams: doc.data['amount_had'] ?? 0,
);
}).toList();
}
I get the error:
The getter 'doc' isn't defined for the class 'QuerySnapshot'
What 's wrong?
Solution 1:[1]
Posting @Dharmaraj comment for better visibility:
You used doc instead of docs. Correct line:
return snapshot.docs.map((doc){
Solution 2:[2]
You migh need call docs not doc. Remember QuerySnapshot -> DocumentSnapshot -> Your Item
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Tuan |
