gpt4 book ai didi

firebase - 聊天消息排序不正确

转载 作者:IT王子 更新时间:2023-10-29 06:43:29 36 4
gpt4 key购买 nike

我将 Firestore 和 Flutter 用于聊天应用。它工作正常,但我看到了这个问题。有时消息不按顺序显示。例如,通常它们被排序为最近的在底部。但我在 iOS 和 Android 模拟器上测试,有时会看到消息没有按顺序显示。例如,我在 iOS 上发送消息,一切正常(按顺序)。然后我在不同的模拟器(例如 Android)上发送,消息显示在顶部,然后开始下降(在 iOS 上发送的消息之上)。

这是我的代码:

            child: new FirestoreAnimatedList(
query: reference
.orderBy('timestamp', descending: true)
.snapshots(),
padding: new EdgeInsets.all(8.0),
reverse: true,
itemBuilder: (_, DocumentSnapshot snapshot,
Animation<double> animation, int x) {
return new Chat(
snapshot: snapshot, animation: animation);
},
),

'时间戳': DateTime.now(),

我试过这个但是同样的问题:

'timestamp': DateTime.now().millisecondsSinceEpoch.toString()

我寻找了数周的答案,但没有找到。谁能帮忙?

最佳答案

您可能会遇到此问题,因为设备报告的时间不同。

要解决这个问题,请使用服务器时间而不是本地时间。这是通过将 timestamp 字段设置为 FieldValue.serverTimestamp() 来完成的。

Documentation .

关于firebase - 聊天消息排序不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53561687/

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