首页 > 解决方案 > Flutter Firestore,按日期排序数据

问题描述

这是我的搜索代码。我正在使用此代码从 Firestore 获取卡。我正在尝试按日期设置我的卡片排序。

我怎样才能做到这一点。感谢帮助。

class SearchService {
      List<Future<QuerySnapshot>> searchByName() {
        return [
          Firestore.instance
              .collection('dis')
              .where('no')
              .getDocuments(),
    
    
        ];
      }
    }

标签: androidfirebaseflutterdartgoogle-cloud-firestore

解决方案


“where”子句不会为您对查询结果进行排序。为此,您将需要使用orderBy。您还需要知道用于订购的日期字段的名称,如文档中所示。

          Firestore.instance
              .collection('dis')
              .orderBy('date')
              .getDocuments(),

如果您没有为每个文档存储日期的字段,您将无法对结果进行排序。


推荐阅读