扑来,无法获取firebase查询
我在Firebase Collection中有一些名称数据,并且在应用程序中获得了新的名称输入,并将数据添加到Firebase中的同一集合中,因此,我正在使用IF条件来检查该名称是否已经存在于Firebase中。但是,如果条件不起作用,我尝试通过创建新功能并返回布尔来解决它。但是没有工作。我如何解决这个问题。从Firebase获取数据不是正确的方法吗?
SaveButton(
onPressed: () {
if (NameController.text.isEmpty) {
Get.snackbar(
'Error:', "Borrower Name can't be empty",
backgroundColor: Colors.red);
} else if (FirebaseFirestore.instance
.collection('lender')
.doc(auth.currentUser!.email)
.collection('borrowers')
.where('Name',
isEqualTo:
NameController.text)
.snapshots()
.isEmpty ==
false) {
Get.snackbar('Error',
'Borrower Name exists, Enter new name',
backgroundColor: Colors.red);
}
}
I have some name data in firebase collection and I am getting new name input in app and adding the data to the same collection in firebase so, I am using an if condition to check if the name already exists in firebase. But the if the condition doesn't work I tried solving it by creating a new function and returning a bool. But didn't work. How do I approach this problem. Is it not the right way to fetch the data from firebase?
SaveButton(
onPressed: () {
if (NameController.text.isEmpty) {
Get.snackbar(
'Error:', "Borrower Name can't be empty",
backgroundColor: Colors.red);
} else if (FirebaseFirestore.instance
.collection('lender')
.doc(auth.currentUser!.email)
.collection('borrowers')
.where('Name',
isEqualTo:
NameController.text)
.snapshots()
.isEmpty ==
false) {
Get.snackbar('Error',
'Borrower Name exists, Enter new name',
backgroundColor: Colors.red);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
。
.isEmpty return Future, So you have to add await to wait until function completed