1

While using geoFlutter fire to get the location nearby me. Some error is occurring. The error is

E/flutter ( 3409): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: The getter 'hash' was called on null.
E/flutter ( 3409): Receiver: null
E/flutter ( 3409): Tried calling: hash

The function I'm calling is here

void nearbyLocations() async {
    var collectionRef = FirebaseFirestore.instance.collection('locations');
    double radius = 10;
    String field = 'position';
    GeoFirePoint center = await getCurrentLocation();
    Stream<List<DocumentSnapshot>> stream = geo
        .collection(collectionRef: collectionRef)
        .within(center: center, radius: radius, field: field, strictMode: true);
    stream.listen((List<DocumentSnapshot> documentList) {
      if (documentList.length > 0) {
        print(documentList.length);
        for (int i = 0; i < documentList.length; i++) {
          GeoPoint pos = documentList[i].data()['position']['geopoint'];
          print(documentList[i].data());
          print(center.distance(lat: pos.latitude, lng: pos.longitude));
        }
      } else {
        print('Nothing');
      }
    });
  }

The above code is place in a file called geoLocator.dart and in a class called GeoLocator and It's called in another dart file like this GeoLocator().nearbyLocations();

On Analysis the error is occurring in this line Stream<List<DocumentSnapshot>> stream = geo.collection(collectionRef: collectionRef).within(center: center,radius: radius, field: field, strictMode: true);

Xor96
  • 424
  • 1
  • 3
  • 13
  • @nvoigt Sorry I couldn't find my mistake. Please help me sort this out – Xor96 Oct 20 '20 at 09:58
  • So what are the values of all those variables in that line? – nvoigt Oct 20 '20 at 09:59
  • @nvoigt Got it thank you nvoigt! The value of center had a null value. – Xor96 Oct 20 '20 at 10:21
  • @nvoigt Your comment helped. I encourage you to put that as an answer. – MrTech Oct 20 '20 at 21:23
  • Matter of fact it *is* an answer. Just not on this question. When someone asks a question that already has an answer here, we call that a "duplicate". You can vote-to-close as duplicate or you can flag it as duplicate if you cannot vote-to-close yet. This way we don't repeat ourselves. If you want to upvote the helpful answer, you can do that on the question that was selected as a duplicate. – nvoigt Oct 21 '20 at 06:02

0 Answers0