简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM