Reputation: 757
I searched in topics with same problem but no one solve mine.
I have this cloud store :
I create this service :
import 'package:cloud_firestore/cloud_firestore.dart';
class FireBaseApi {
getData() {
try {
var databse = FirebaseFirestore.instance.collection('mycollection');
return databse;
} catch (e) {
print(e);
return null;
}
}
}
and used it like this :
return StreamBuilder(
stream: FireBaseApi().getData().snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Scaffold(
body: Center(
child: SizedBox(
width: 100,
height: 100,
child: CircularProgressIndicator())),
);
} else {
print('length = ${snapshot.data.documents}');
return SafeArea(
child: Scaffold(
body: ListView( children: [Text('Noj Clinic'),
child: GridView.builder(
itemCount: snapshot.data.size, .......etc
)],)
I gave error Class 'QuerySnapshot' has no instance getter 'documents'.
and this is shown :
Upvotes: 0
Views: 411
Reputation: 7686
Change documents
to docs
. That should fix it.
So this
print('length = ${snapshot.data.documents}');
should become:
print('length = ${snapshot.data.docs}');
https://pub.dev/documentation/cloud_firestore/latest/cloud_firestore/QuerySnapshot/docs.html
Upvotes: 2