I've just upgraded to cloud firestore: ^2.1.0
and I have an error on snapshots.data?.documents
or snapshots.data?.docs
with message The getter 'documents' isn't defined for the type 'Object'. in the above code :
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: FirebaseFirestore.instance.collection('Courses').snapshots(),
builder: (context1, snapshot) {
//just add this line
if (snapshot.data == null) return CircularProgressIndicator();
return ListView.builder(
itemCount: snapshot.data?.documents.length,
itemBuilder: (context2, index) {
return GestureDetector(
onTap: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => DetailCourseScreen(
snapshot.data?.documents[index]['title'],
snapshot.data?.documents[index]['storage'],
index),
),
),
child: _buildCourseList(
context2, snapshot.data?.documents[index], index),
);
},
);
},
);
}
And here is my pubspec.yaml
:
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
cloud_firestore: ^2.1.0
firebase_core: ^1.1.1
firebase_storage: ^8.0.6
firebase_image: ^1.0.1
I understand your confusion. Accessing cloud firestore's data has gotten kind of weird since the update on cloud_firestore 2.0.0. You can access your data with the following code:
You can read more about this update here: https://pub.dev/packages/cloud_firestore/changelog#200