NoSuchMethodError:在空调用getter“哈希”

时间:2020-10-20 06:34:38

标签: firebase flutter dart google-cloud-firestore

虽然使用geoFlutter火来获取我附近的位置。发生一些错误。错误是

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

我正在调用的功能在这里

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');
      }
    });
  }

上面的代码放置在名为geoLocator.dart的文件中,并位于名为GeoLocator的类中,并在另一个GeoLocator().nearbyLocations();

这样的dart文件中调用

分析时,此行Stream<List<DocumentSnapshot>> stream = geo.collection(collectionRef: collectionRef).within(center: center,radius: radius, field: field, strictMode: true);中发生了错误

0 个答案:

没有答案