如何在模型中对代表特定收藏的火库文件的特定项目进行排序?(P.S:点击下面的问题,得到了很好的回答)

问题描述 投票:0回答:1

点击这里查看以前的版本好解决的问题,由我和其他人

我想... 模型中的项目,它代表了特定集合的火库文档,同时这个模型还包含了用户的文档ID(将根据距离的远近进行排序) 收集 "用户",我将带来这些文件只从 "用户" 集。我计算了从当前用户到其他用户的距离。 而我想为这个用户带来最近的用户。我已经尝试了以下代码。

ScreenShot: [在粉色方框区域,完成整个计算和分配,并从消防基地带来文件。][In the pink box area, whole calculation is done and assigned and documents brought from firebase]2

得到了错误。

收到这个错误:"未处理的异常: "Unhandled Exception: PlatformException(error, Invalid Query. 'in'过滤器的值数组中不能包含'null'。

详细代码。

温度模型。

     class certainrangeusers {
     final String id;
     final double away;
     final GeoPoint userpoint;
      certainrangeusers({this.id, this.away, this.userpoint});
      }

变量:

   List<certainrangeusers> info= [];

代码: Temp模型: 变量: 代码:

    getUsers() async
      {
       double radius = 0.3;
       String field = "GeoPosition";
       print(currentUser.point.longitude);
             GeoFirePoint center = geo.point(latitude: currentUser.point.latitude,
         longitude: currentUser.point.longitude);

       var collectionRef = Firestore.instance.collection('user_locations').document(currentUser.pincode)
         .collection('Users_comp  lete_address_and_geopoint');

          this.stream =  geo.collection(collectionRef: collectionRef)
              .within(center: center, radius: radius, field: field, strictMode: false);

            Future<List<certainrangeusers>> users1 =  stream.first.then((documents) => documents.map((doc) => 
          certainrangeusers(
         id: doc['userPhone'],
        userpoint : doc['GeoPosition']['geopoint'],
       )
        ).toList());

          users1.then((val) async{
           for(var value in val){
            info.add(certainrangeusers(
            //away: await Geolocator().distanceBetween(currentUser.point.latitude,currentUser.point.longitude, value.userpoint.latitude, value.userpoint.longitude),
              away: center.distance(lat: value.userpoint.latitude,lng: value.userpoint.longitude),
                         ));
                  info.sort((a,b) => a.away.compareTo(b.away));
                }
              List ids = [];
              for(var value in info){
             ids.add(value.id);
                 }
            QuerySnapshot snapshot = await Firestore.instance.collection('users').where('id', whereIn: ids).getDocuments();
           List<User> users = snapshot.documents.map((doc) => User.fromDocument(doc)).toList();
            setState(() {
            this.users = users;
                 });
              });
          }
firebase flutter google-cloud-firestore
1个回答
2
投票

错误信息是告诉你,你用于这个查询的数组中不能有一个空值。

Firestore.instance
    .collection('users')
    .where('id', whereIn: ids)
    .getDocuments();

你必须弄清楚为什么要这样做 ids 包含一个空值,并修复它。 根据你在这里显示的内容,我们看不出这是从哪里来的。

© www.soinside.com 2019 - 2024. All rights reserved.