【发布时间】:2021-04-25 22:17:44
【问题描述】:
我有一个使用 firestore 的应用程序,当用户单击按钮时,我添加了一个文档,在其创建后,我还将其 documentId 添加到 field 中,该字段是由 firestore 生成的字母数字字符串。我的问题是,如果用户在没有互联网的情况下单击按钮,然后关闭应用程序并通过互联网连接打开它,文档就会创建,但它内部的 Id 当然是空的,因为程序停止执行。有没有办法让我坚持下去?
例如
DocumentReference documentReference =
await FirebaseFirestore.instance.collection('sth').add(map); //map has a 'docId' key
await FirebaseFirestore.instance
.collection('sth')
.doc('${documentReference.id}')
.update({'docId': documentReference.id});
更新的没有离线持久化,有什么办法解决吗?
【问题讨论】:
-
尝试使用
set而不是update -
不适用于set
标签: flutter google-cloud-firestore offline