Reputation: 110
FirebaseFirestore.instance.collection('locations').getDocuments().then((docs){
if(docs.documents.isNotEmpty){
for(int i=0 ;i<docs.documents.length;i++){
initMarker(docs.documents[i].data , docs.documents[i].documentID);
}
}
});
}
init Marker Snap
void initMarker(request,requestId){
var markerIdVal = requestId;
final MarkerId markerId = MarkerId(markerIdVal);
//creating a new Marker
final Marker marker = Marker(
markerId:markerId,
position:LatLng(request['loc_Coords'].lattitude,request['loc_Coords'].longitude),
infoWindow:InfoWindow(
title:request['loc_Name'],
snippet:request['loc_Description'],
),
);
setState((){
markers[markerId] = marker;
print(markerId);
});
The method 'getDocuments' isn't defined for the type 'CollectionReference'.
Please could you help me to get rid this error?
Upvotes: 3
Views: 4681
Reputation: 86
If you are reading the collection once off use the method get() instead of getDocuments().
Upvotes: 7