【问题标题】:How to combine Firestore (where, orderBy with start After cursor in flutter)如何结合 Firestore(其中,orderBy 与 start After 光标在颤动中)
【发布时间】:2019-07-11 13:34:02
【问题描述】:

如何结合Firestore(where, orderBy with start After cursor in flutter)

getMoreData() async {
    if (moreDataAvailable == false) {
      print("no more data");
      return;
    }
    if (gettingMoreData == true) {
      return;
    }
    gettingMoreData = true;

    Firestore.instance
        .collection('clients')
        .where('alarm', isEqualTo: true)
        .orderBy('nameFs')
        .startAfter([_lastDocument.data['nameFs']])
        .limit(perPage)
        .getDocuments()
        .then((snapshot) {
          setState(() {
            if (snapshot.documents.length < perPage) {
              moreDataAvailable = false;
            }
            alarmData.addAll(snapshot.documents);
            _lastDocument = snapshot.documents[snapshot.documents.length - 1];
            isGet = true;
            gettingMoreData = false;
          });
          initialData.addAll(alarmData);
        });
  }

我正在尝试在我的颤振应用程序查询中进行分页,无需 orderBy 但是如果没有我的应用程序中没有分页,我还希望在哪里工作我是新的 Flutter 请任何人都可以给我解决方案。

【问题讨论】:

    标签: flutter


    【解决方案1】:

    试试这个包 - paginate_firestore

    你只需要像这样传递itemBuilderquery,它就会为你实现分页,

          PaginateFirestore(
            itemBuilder: (context, documentSnapshot) => ListTile(
              leading: CircleAvatar(child: Icon(Icons.person)),
              title: Text(documentSnapshot.data['name']),
              subtitle: Text(documentSnapshot.documentID),
            ),
            // orderBy is compulsary to enable pagination
            query: Firestore.instance.collection('users').orderBy('name'),
          )
    

    【讨论】:

      猜你喜欢
      • 2018-06-14
      • 1970-01-01
      • 2019-07-17
      • 1970-01-01
      • 2019-09-23
      • 2021-04-30
      • 1970-01-01
      • 2021-08-01
      • 2018-12-15
      相关资源
      最近更新 更多