Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 930
Deshan Maduranga Avatar asked Jul 01 '26 10:07

Deshan Maduranga


1 Answers

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

like image 106
William Cardenas Avatar answered Jul 05 '26 16:07

William Cardenas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!