简体   繁体   English

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

[英]I need help making a compound query from Dart-Flutter to FireBase

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.

I am currently generating by date range我目前正在按日期范围生成

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

I tried different ways but I did not get results, I am sorry if there are errors but I am a beginner.我尝试了不同的方法,但没有得到结果,如果有错误,我很抱歉,但我是初学者。

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

             }

I need to fix the data so that it appears in my pdf generation like this.我需要修复数据,以便它像这样出现在我的 pdf 代中。

Filtered by dates and this is data of a single type按日期过滤,这是单一类型的数据

Do not use .toIso8601String() , Firestore offers a data type called Timestamp , you can use Timestamp.fromDate(to) and you can get a Timestamp object that you can compare with.不要使用.toIso8601String() ,Firestore 提供了一种名为Timestamp的数据类型,您可以使用Timestamp.fromDate(to)并且可以获得可以与之比较的Timestamp object。 Make sure to have the same data type in your database (Do not save the date as String there is a choice called Timestamp ) see timestamp on firestore .确保数据库中的数据类型相同(不要将日期保存为String ,有一个名为Timestamp的选项)请参阅 firestore 上的时间戳

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我需要帮助将跨平台 flutter 应用程序链接到 windows 上的 firebase - I need help linking cross platform flutter app to firebase on windows Firebase 9(模块化)上的复合查询 - Compound query on Firebase 9 (modular) Firebase 复合查询 AND + OR - Firebase compound query AND + OR Cloud Firestore Firebase Collection ref 上的 IN 查询是否有 Flutter/Dart 等价物? - Is there a Flutter/Dart equivalent for the IN query on a Cloud Firestore Firebase Collection ref? 如何使用 Flutter/Dart 从 Firebase 实时数据库中读取数据 - How to read data from Firebase Realtime database using Flutter/Dart 如何获取从 Dart Flutter Firebase 检索到的数据的值? - How to get value of data retrieved from Dart Flutter Firebase? 我想检索存储在作为数组存储的 firebase 中的数据。 然后我需要从 firebase 获取数组并将其存储在 flutter 列表中 - I want to retrieve data stored in firebase which is stored as an array. then I need to get the array from firebase and store it in a list in flutter 无法从 Dart Flutter FireBase 中提取数据 - Can't pull data from Dart Flutter FireBase Dart Flutter 顺序 firebase_auth 错误 - Dart Flutter sequential firebase_auth errors Firebase Firestore - 复合查询中包含多个数组 - Firebase Firestore - Multiple array-contains in a compound query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM