gpt4 book ai didi

firebase - 如何在 Flutter 中正确调用 FirebaseFirestore.instance.clearPersistence()?

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

我和这个人面临同样的问题 question
但他接受的答案对我没有帮助。
问题:
当一个用户退出时,另一个不同的用户登录时,由于 firebase 缓存系统,我的应用程序上显示的所有数据都来自前一个退出用户。我搜索了这个问题并找到了一个解决方案,它包括调用这个方法:

FirebaseFirestore.instance.clearPersistence();
但是无论何时何地,我放置这行代码时,都会抛出一个异常,说在客户端运行时我无法调用此方法:

Exception has occurred.PlatformException (PlatformException(failed-precondition, Operation was rejected because the system is not in a state required for the operation's execution. If performing a query, ensure it has been indexed via the Firebase console., {code: failed-precondition, message: Operation was rejected because the system is not in a state required for the operation's execution. If performing a query, ensure it has been indexed via the Firebase console., nativeErrorMessage: Persistence cannot be cleared while the client is running., nativeErrorCode: 9}))


那么,如何调用这个方法呢?或者更好,有没有最好的方法来解决这个问题?

最佳答案

看来有必要终止FirebaseFirestore.instance第一的。
在我的注销方法结束时,我调用:

await FirebaseFirestore.instance.terminate();
await FirebaseFirestore.instance.clearPersistence();
我没有收到任何错误,一切似乎都在正常工作。

关于firebase - 如何在 Flutter 中正确调用 FirebaseFirestore.instance.clearPersistence()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63930954/

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