gpt4 book ai didi

firebase - 刷新以加载新数据并滚动以分页数据Flutter Firestore

转载 作者:行者123 更新时间:2023-12-03 03:32:53 25 4
gpt4 key购买 nike

我有一个名为“Feeds”的Firestore集合,其中包含给定用户的feed(例如Instagram)的帖子列表。 View 加载后,我会按时间调用远景和订单

var userPostsDocumentSnapshot = await _feeds
.document(userUid)
.collection(items)
.orderBy('postDateTime', descending: true)
.getDocuments();
我最初使用的是流,但是当新数据添加到用户的Feed中时,我不希望它自动显示,我希望下拉菜单加载新数据。但是,我还想通过在向下滚动(从最新到最旧)时对数据进行分页来提高效率,以使其更有效率。滚动时如何既能下拉加载新数据又能分页数据?

最佳答案

对于下拉菜单,您只想再次执行查询。
对于分页,我使用了一个光标as documented here。例如,根据您使用UI的方式,可以将查询限制为特定数量的文档。
因此,对于您的查询,可能会执行以下操作:

var userPostsDocumentSnapshot = _feeds
.document(userUid)
.collection(items)
.orderBy('postDateTime', descending: true)
.limit(10);
然后,当您实际抓取文档时,请存储对最后一个文档的引用:
var docsnaps = await userPostsDocumentSnapshot.getDocuments();
var last = docsnaps.docs[documentSnapshots.docs.length-1];
然后在分页时,对查询使用稍微的变化:
      ...  _feeds
.document(userUid)
.collection(items)
.orderBy('postDateTime', descending: true)
.startAfter(last);

关于firebase - 刷新以加载新数据并滚动以分页数据Flutter Firestore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62897142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com