Deshan Maduranga
Deshan Maduranga

Reputation: 110

The method 'getDocuments' isn't defined for the type 'CollectionReference'

   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

Answers (1)

William Cardenas
William Cardenas

Reputation: 86

If you are reading the collection once off use the method get() instead of getDocuments().

Upvotes: 7

Related Questions