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?
CodePudding user response:
Posting @Dharmaraj comment for better visibility:
You used doc
instead of docs
. Correct line:
return snapshot.docs.map((doc){
CodePudding user response:
You migh need call docs
not doc
. Remember QuerySnapshot
-> DocumentSnapshot
-> Your Item