flutter / dart如何检查Firestore中是否存在文档? [英] flutter / dart How can check if a document exists in firestore?
本文介绍了flutter / dart如何检查Firestore中是否存在文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用bool查询cloudfirestore中是否存在文档。不幸的是,我的代码不起作用
I try to query using a bool if a document exists on the cloudfirestore or not. Unfortunately, my code does not work
我尝试了以下操作,但bool并没有改变。
I tried the following, but the bool does not change.
getok() {
bool ok;
Firestore.instance.document('collection/$name').get().then((onexist){
onexist.exists ? ok = true : ok = false;
}
);
if (ok = true) {
print('exist');
} else {
print('Error');
}
}
推荐答案
you可以尝试这样做,尽管我使用的是IDS
you could try doing it this way though im usi IDS
static Future<bool> checkExist(String docID) async {
bool exists = false;
try {
await Firestore.instance.document("users/$docID").get().then((doc) {
if (doc.exists)
exists = true;
else
exists = false;
});
return exists;
} catch (e) {
return false;
}
}
这篇关于flutter / dart如何检查Firestore中是否存在文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文