flutter - 如何结合 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 但没有我在我的应用程序中没有得到分页也希望在哪里工作我是颤振新手,请任何人都可以给我解决方案。
解决方案
试试这个包 - paginate_firestore。
您只需要通过itemBuilder
并query
喜欢这个,它就会为您实现分页,
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'),
)
推荐阅读
- sql - 简单的 JSON 数组到行
- angular - 尝试修改 Ionic 3 中某些页面中的硬件后退按钮行为
- clips - CLIPS 6.3 IF 语句
- java - Is it possible to embed a Python/Django app in a Java Web App?
- amazon-web-services - Why should I combine SNS and Firebase GCM
- android - 如何在折叠工具栏布局中更改 scrim 侦听器中的位置?
- vba - date1 before (1/month(date1)+2/month(year1)) vba 访问
- android - 将数据插入本地存储失败
- postgresql - 如何将 Cdash 与 gitlab 内部 postgres 数据库连接
- spring-boot - 在 Jetty 线程中等待