0

我正在使用以下代码从Firestore数据库中获取文档Flutter Application,该代码使用类别过滤器进行查询以从数据库中检索文档。它工作正常。现在我需要实现的只是在这种情况下的分页,我检查了几个示例,但找不到适合这种用例的示例。虽然我能够为没有过滤器实现的列表实现分页。

在这种情况下我应该怎么做?

Query query;
    if (category != null){
      query = widget._firestore.collection("items").where("itemCategory", isEqualTo: category ).orderBy("timestamp", descending: true);
    }
    else {
       query = widget._firestore.collection("items").orderBy(
          "timestamp", descending: true);
    }

//inside scaffold
StreamBuilder<QuerySnapshot>(
            stream: query.snapshots(),
            builder: (context, snapshot) {

              if (!snapshot.hasData){
                return SliverFillRemaining(

                );
              }
              return SliverList(
                  delegate: new SliverChildBuilderDelegate(
                        (context, index) {


                          String itemTitle = snapshot.data.documents[index]['itemTitle'];


          return  CardItem(itemTitle:itemTitle                     
                    },
                    childCount:
                    snapshot.hasData ? snapshot.data.documents.length : 0,
                  ));
            },
          ),
4

0 回答 0