firebase - 使用 Firebase 中的 StartAt 和 Flutter 时间戳
问题描述
我在 Firestore 上保存了一些带有时间戳属性的帖子,然后我查询这些帖子按时间戳排序。我正在尝试创建一个“loadMore”函数,然后当用户滚动到底部并加载更多帖子时工作。
我以这种方式保存帖子:
Firestore.instance
.collection('posts')
.add(<String, dynamic> {
'content': 'content,
'likes': 0,
'comments': 0,
'timestamp': DateTime.now(),
})
并尝试以这种方式查询:
Firestore.instance
.collection('posts')
.orderBy('timestamp', descending: true)
.startAfter(
[]..add(posts.last.timestamp)
)
..limit(5)
但是,它一直忽略“startAfter”并返回一个从集合的第一个元素开始而不是下一个元素的列表。
希望使用这种类型的查询获得帮助:)
解决方案
将 DateTime 转换为 Unix 日期时间
'timestamp': DateTime.now().toUtc().millisecondsSinceEpoch
推荐阅读
- elasticsearch - 用于弹性搜索的边缘 N-gram 中的连字符
- bash - 打开 tmux 终端的快捷方式
- ios - 线程 1:致命错误:NSArray 元素无法匹配 Swift Array 元素类型
- xamarin - 绑定文本未以 xamarin 形式显示
- hive - 如何在 hive 查询中实现 LEFT/RIGHT OUTER JOIN 来替换 NOT IN?
- ios - 多个应用程序通过应用程序组对 CoreData 的不同权限
- spring-integration - 在“MessageGroupStore”中只能注册一个“UniqueExpiryCallback”实例
- c# - StreamReader 数据输入到字典
- python - 如何获取 NumPy 掩码数组的最后一个非零值?
- javascript - async-await 在 JavaScript 中是如何工作的?使函数异步使其异步吗?