Firebase Flutter 应用程序有没有办法在离线应用程序重启后保留数据?

Upa*_*Jah 2 firebase flutter

我正在使用 firebase 动画列表来显示存储在 firebase 实时数据库中的项目列表。

现在,当我在离线状态下启动应用程序(应用程序被杀死后)时,列表不会加载。

是否有内置方法可以为这个用例离线存储数据(由 firebase 提供)?或者我需要存储在一些离线数据库中吗?

我已经检查了https://firebase.google.com/docs/database/android/offline-capabilities但找不到这个特定的用例。

相关问题https://github.com/flutter/flutter/issues/19271

Gün*_*uer 5

听起来好像 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