Flutter 如何检查具有Flatter future的Firestore中是否存在子集合<;布尔>;
如果存在某个子集合,我在Firestore查询中返回Flutter 如何检查具有Flatter future的Firestore中是否存在子集合<;布尔>;,flutter,google-cloud-firestore,future,Flutter,Google Cloud Firestore,Future,如果存在某个子集合,我在Firestore查询中返回true/false语句时遇到问题 这是我的密码: Future<bool> checkIfCollectionExist( String collectionName, String productId) async { await _db .collection('products') .doc(productId) .collection(collecti
true
/false
语句时遇到问题
这是我的密码:
Future<bool> checkIfCollectionExist(
String collectionName, String productId) async {
await _db
.collection('products')
.doc(productId)
.collection(collectionName)
.limit(1)
.get()
.then((value) {
return value.docs.isNotEmpty;
});
}
Future checkIfCollectionExist(
String collectionName,String productId)异步{
等待
.集合(“产品”)
.doc(productId)
.集合(集合名称)
.限额(1)
.get()
.然后((值){
返回值.docs.isNotEmpty;
});
}
因此,我得到了Future
的实例,但我需要true
/false
答案。
我在这里做错了什么?使用
Future<bool> checkIfCollectionExist(String collectionName, String productId) async {
var value = await _db
.collection('products')
.doc(productId)
.collection(collectionName)
.limit(1)
.get();
return value.docs.isNotEmpty;
}
Future checkIfCollectionExist(String collectionName,String productId)异步{
var值=等待_db
.集合(“产品”)
.doc(productId)
.集合(集合名称)
.限额(1)
.get();
返回值.docs.isNotEmpty;
}
或
Future checkIfCollectionExist(字符串collectionName,字符串productId){
返回_db
.集合(“产品”)
.doc(productId)
.集合(集合名称)
.限额(1)
.get()
.然后((值){
返回值.docs.isNotEmpty;
});
}
Future<bool> checkIfCollectionExist(String collectionName, String productId) {
return _db
.collection('products')
.doc(productId)
.collection(collectionName)
.limit(1)
.get()
.then((value) {
return value.docs.isNotEmpty;
});
}