我正在使用 firebase 动画列表来显示存储在 firebase 实时数据库中的项目列表。
现在,当我在离线状态下启动应用程序(应用程序被杀死后)时,列表不会加载。
是否有内置方法可以为这个用例离线存储数据(由 firebase 提供)?或者我需要存储在一些离线数据库中吗?
我已经检查了https://firebase.google.com/docs/database/android/offline-capabilities但找不到这个特定的用例。
听起来好像 FirebaseDatabase.setPersistenceEnabled
/// Attempts to sets the database persistence to [enabled].
///
/// This property must be set before calling methods on database references
/// and only needs to be called once per application. The returned [Future]
/// will complete with `true` if the operation was successful or `false` if
/// the persistence could not be set (because database references have
/// already been created).
///
/// The Firebase Database client will cache synchronized data and keep track
/// of all writes you’ve initiated while your application is running. It
/// seamlessly handles intermittent network connections and re-sends write
/// operations when the network connection is restored.
///
/// However by default your write operations and cached data are only stored
/// in-memory and will be lost when your app restarts. By setting [enabled]
/// to `true`, the data will be persisted to on-device (disk) storage and will
/// thus be available again when the app is restarted (even when there is no
/// network connectivity at that time).
Future<bool> setPersistenceEnabled(bool enabled) async {
// ...
}
Run Code Online (Sandbox Code Playgroud)
来自firebase_database/lib/src/firebase_database.dart
| 归档时间: |
|
| 查看次数: |
2060 次 |
| 最近记录: |