user14845003
user14845003

Reputation: 93

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?

Upvotes: 1

Views: 244

Answers (2)

Tuan
Tuan

Reputation: 2421

You migh need call docs not doc. Remember QuerySnapshot -> DocumentSnapshot -> Your Item

Upvotes: 0

mdobrucki
mdobrucki

Reputation: 522

Posting @Dharmaraj comment for better visibility:

You used doc instead of docs. Correct line:

 return snapshot.docs.map((doc){

Upvotes: 1

Related Questions