Nar*_*eit 4 dart firebase flutter google-cloud-firestore
我需要检查数据是否已成功写入 Firestore,因此如果成功,我需要显示一个弹出窗口,显示数据已写入,或者如果数据未写入,我需要显示一个弹出窗口,显示任务失败,所以我应该使用未来的构建器吗?就是这样做的方法
每个 Firestore 操作都是 Promise,因此它有.then()和.catch()方法来处理任务是成功还是失败。
例如,你可以做这样的事情。
firestoreInstance.collection("Users").document('123456').updateData({
"username" : 'white_devil'
}).then((result) {
print("Success!");
}).catch((error){
print("Error!")
});
Run Code Online (Sandbox Code Playgroud)
不仅在 上updateData(),您还可以在setData()、add()、get()以及getDocuments()所有返回 Promise 的操作中使用这种情况。
| 归档时间: |
|
| 查看次数: |
2613 次 |
| 最近记录: |