首页 > 解决方案 > 如何结合 Firestore(其中,orderBy 与 start After 光标在颤动中)

问题描述

如何结合 Firestore(其中,orderBy 与 start After 光标在颤动中)

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

解决方案


试试这个包 - 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'),
      )

推荐阅读