【问题标题】:How can i clear flutter firestore cache我如何清除颤动的 Firestore 缓存
【发布时间】:2020-02-04 15:10:36
【问题描述】:

我将databese中的一个值转换为列表中的地图,但它仍然看到旧的 那么如何清除 Firestore 缓存呢?

Firestore.instance.settings(persistenceEnabled: false);

我使用此代码,但给我错误

未处理的异常:PlatformException(错误,FirebaseFirestore 已启动,无法再更改其设置。您只能在调用 FirebaseFirestore 对象上的任何其他方法之前调用 setFirestoreSettings()。,null)

【问题讨论】:

标签: flutter google-cloud-firestore


【解决方案1】:

错误消息不是关于清除缓存,而是关于您在代码中更改 Firestore 设置的位置。具体来说,您只能在第一次调用Firestore.instance 时更改设置,在您的情况下,在您调用Firestore.instance.settings(persistenceEnabled: false) 之前会发生另一个调用。

解决方案是找到另一个调用,并确保 Firestore.instance.settings(persistenceEnabled: false) 是您的应用对 Firestore 的第一个调用。

【讨论】:

  • 无论我放在哪里,它都会给出相同的错误。还有其他方法吗?
  • 这意味着在您尝试更改设置之前还有另一个 Firestore 调用发生。如果您编辑您的问题以包含 MCVE,我们可能会更好地帮助您解决问题的来源。
【解决方案2】:

你可以很好地解决这个问题:

FirebaseFirestore.instance.settings =
    Settings(persistenceEnabled: false);

【讨论】:

    猜你喜欢
    • 2019-11-25
    • 2020-12-24
    • 1970-01-01
    • 1970-01-01
    • 2020-02-05
    • 2017-03-18
    • 2019-03-08
    • 2014-08-19
    • 1970-01-01
    相关资源
    最近更新 更多