Dart Flatter Firestore离线持久化
我想使用离线firestore persistent,但我没有得到正确的代码。在kotlin教程中,这样说:Dart Flatter Firestore离线持久化,dart,flutter,google-cloud-firestore,Dart,Flutter,Google Cloud Firestore,我想使用离线firestore persistent,但我没有得到正确的代码。在kotlin教程中,这样说: db.collection("members").document() .addSnapshotListener(object : EventListener<DocumentSnapshot> { override fun onEvent(snapshot: DocumentSnapshot?,
db.collection("members").document()
.addSnapshotListener(object : EventListener<DocumentSnapshot> {
override fun onEvent(snapshot: DocumentSnapshot?,
e: FirebaseFirestoreException?) {
if (e != null) {
Log.w(ContentValues.TAG, "Listen error", e)
err_msg.text = e.message
err_msg.visibility = View.VISIBLE;
return
}
snapshot?.reference?.set(data)
val intent = Intent()
setResult(Activity.RESULT_OK, intent)
this@FormActivity.finish()
}
}
)
也可以试试这个:
Firestore.instance.collection("hega").add(data);
在线时两者都可以工作,但设备离线时不工作(使用飞行模式)
更新:
所以上面的代码实际上是离线工作的
Firestore.instance.collection("hega").document().setData(data);
我只需要将流侦听器设置为文档快照,以查看数据是否已添加到本地缓存。但另一个问题是,当设备联机时,脱机数据不会同步到服务器。您是否在Flatter中使用kotlin代码?不,我刚刚在kotlin上找到了如何脱机使用firestore的教程。我想在颤振飞镖上使用它。当设备上线时,你找到解决方案了吗?Hi@Rickdrio nothing todo,所有这些都已经由sdk处理。
Firestore.instance.collection("hega").document().setData(data);