我需要帮助进行从Dart-Flutter到FireBase的复合查询

myzjeezk  于 2022-12-05  发布在  Flutter
关注(0)|答案(1)|浏览(103)
Hello, I need help to make a query ordered by date and grouped by type, to obtain an array for each type according to the selected date range. i am working using dart-flutter and firebase.

我目前正在按日期范围生成

Future<List<JobsData>> getEntry({ DateTime from, DateTime to}) async {
    try {
      //print(from?.toIso8601String());
     
      QuerySnapshot<Map<String, dynamic>> _snap = await _firestore
          .collection("applications")
          //.where("statusLabel", isEqualTo: "Avalaible")
          .where("dateOfApplication",
          isGreaterThanOrEqualTo: from?.toIso8601String())
          .where("dateOfApplication", 
          isLessThanOrEqualTo: to?.toIso8601String())
         //.where("statusLabel", isEqualTo: "Finalized")
          .orderBy("dateOfApplication")
          //.groupBy("userApliedId")
          .get();
      return _snap.docs.map((e) => JobsData.fromJson(e.data())).toList() ;
    } on FirebaseException catch (e) {
      throw e;
    }
  }

我尝试了不同的方法,但我没有得到结果,我很抱歉,如果有错误,但我是一个初学者。

for (var i=0; i < jobsData.length; i++) {
              var sorted = jobsData;
              sorted.sort((a, b) => a.userApliedId.compareTo(b.userApliedId)
               );
           
             if (sorted[i].userApliedId == sorted[i].userApliedId && sorted[i].statusLabel == 'Finalized'){
              print(sorted[i].idJob);
              print(sorted[i].jober);
              print(sorted[i].customer);
              print(sorted[i].date);
              print(sorted[i].statusLabel);
              print(sorted[i].imageUrl);

              final datas = sorted
        .map((i) => [
          i.imageUrl,
              i.userApliedId,
             // e.id,
              i.date,
              i.Actividad,
              i.customer,
              i.pago,
              i.statusLabel,
              i.jober,
              i.imageUrl.toString().split(" ").first,
            // e.stages.toList(),
            ])
        .toList();
        print(datas);

             }

我需要修复的数据,使它出现在我的pdf生成这样。
Filtered by dates and this is data of a single type

huus2vyu

huus2vyu1#

不要使用.toIso8601String(),Firestore提供了一个名为Timestamp的数据类型,您可以使用Timestamp.fromDate(to),并可以获得一个可以与之比较的Timestamp对象。请确保您的数据库中具有相同的数据类型(不要将日期保存为String,有一个名为Timestamp的选项)see timestamp on firestore

.where("dateOfApplication",
          isGreaterThanOrEqualTo: Timestamp.fromDate(from!))
          .where("dateOfApplication", 
          isLessThanOrEqualTo:Timestamp.fromDate(to!))

相关问题