flutter - 保持 firesotrore 集合离线可用并在前台同步

标签 flutter google-cloud-firestore

保持收集数据离线可用(0 - 100 个文档)并在连接可用时在应用程序启动时同步它的最佳方法是什么?

UPD:我正在寻找 setPersistenceEnabled,但是否可以保证我的收藏在第一次检索后会被缓存?

最佳答案

如果您调用 setPersistenceEnabled(true),这些文档将可以离线使用并在连接再次可用时同步(不一定在应用程序启动时)。检查文档: https://firebase.google.com/docs/database/android/offline-capabilities

By enabling persistence, any data that the Firebase Realtime Database client would sync while online persists to disk and is available offline, even when the user or operating system restarts the app. This means your app works as it would online by using the local data stored in the cache. Listener callbacks will continue to fire for local updates.

另请注意,当您使用此功能时,您的监听器将在应用程序启动时被调用两次!一个 - 用于离线(缓存)数据,第二个 - 在线(从 firebase 读取)。

关于flutter - 保持 firesotrore 集合离线可用并在前台同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54304004/

相关文章:

flutter - 从导航堆栈弹出后打开屏幕时调用哪个函数?

parsing - Flutter:通过BottomNavigationBar中的页面解析数据。错误:在初始值设定项中只能访问静态成员

flutter - Flutter:滚动堆栈小部件

android-studio - 设备未在 Android Studio 中显示并带有 flutter

javascript - Firestore - 无法编码值 - 使用 Promise.all() 和 MongoDB Insert 添加文档时

Flutter Provider select - 如何处理复杂的返回类型,如列表或 map

javascript - 使用 GEOFirestore 获取附近的 GEO 结果

firebase - StreamBuilder返回null

javascript - Firestore 手动输入索引?

java - Flutter - 任务 ':cloud_firestore:compileDebugJavaWithJavac' 执行失败