将数据从Firebase存储到SQLite或在flutter中脱机的最佳方法是什么? [英] What is the best way to store data from Firebase to SQLite or offline in flutter?

查看:78
本文介绍了将数据从Firebase存储到SQLite或在flutter中脱机的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,当用户离线时,我希望数据存储在本地数据库中,然后与Firebase同步数据。

In my app when user is offline, I want data to store in local db and then sync data with firebase.

推荐答案

FireStore和实时数据库都具有脱机持久性。

Both FireStore and Realtime Database have offline persistence.

Firestore:

Firestore :

Firestore.instance.settings(persistenceEnabled: true)

对于Firebase Realtime数据库,您不需要任何特定于设置的内容。脱机连接是自动的。因此,以下代码可以解决问题:

In the case of Firebase Realtime database, you don't need anything specific to set-up. Offline connectivity is automatic. So, the following line does the trick :

databaseReference.child(dbKey).set(data);

这篇关于将数据从Firebase存储到SQLite或在flutter中脱机的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆