[Here is the error] I've created constructors in another class but it ain't working.
Here is the code...
body: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection("products").snapshots(),
builder: (context, snapshot) {
return !snapshot.hasData
? Center(child: CircularProgressIndicator())
: ListView.builder(
itemCount: snapshot.data.docs.length,
itemBuilder: (context, index) {
DocumentSnapshot data = snapshot.data.docs[index];
return ProductItem(
documentSnapshot: data,
id: data.id,
isFavourite: data['isFavourite'],
imageUrl: data['imageUrl'],
productName: data['productName'],
productPrice: data['productPrice'],
);
},
);
},
),
);
}
}
You are using ^0.14.0. Calling [] directly is deprecated
body: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection("products").snapshots(),
builder: (context, snapshot) {
return !snapshot.hasData
? Center(child: CircularProgressIndicator())
: ListView.builder(
itemCount: snapshot.data.docs.length,
itemBuilder: (context, index) {
DocumentSnapshot data = snapshot.data.docs[index];
return ProductItem(
documentSnapshot: data,
id: data.id,
isFavourite: data.data()['isFavourite'],
imageUrl: data.data()['imageUrl'],
productName: data.data()['productName'],
productPrice: data.data()['productPrice'],
);
},
);
},
),
);
}
}
Try this,
body: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection("products").snapshots(),
builder: (context, snapshot) {
return !snapshot.hasData
? Center(child: CircularProgressIndicator())
: ListView.builder(
itemCount: snapshot.data.docs.length,
itemBuilder: (context, index) {
DocumentSnapshot data = snapshot.data[index];
Map getDocs = data.data;
return ProductItem(
documentSnapshot: data,
id: data.id,
isFavourite: getDocs['isFavourite'],
imageUrl: getDocs['imageUrl'],
productName:getDocs['productName'],
productPrice: getDocs['productPrice'],
);
},
);
},
),
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With