扑来,无法获取firebase查询

发布于 2025-02-09 21:43:37 字数 1364 浏览 2 评论 0原文

我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放赐 2025-02-16 21:43:37

await FirebaseFirestore.instance
.collection('lender')
.doc(auth.currentUser!.email)
.collection('borrowers')
.where('Name',isEqualTo:NameController.text)
.snapshots()
.isEmpty

.isEmpty return Future, So you have to add await to wait until function completed

await FirebaseFirestore.instance
.collection('lender')
.doc(auth.currentUser!.email)
.collection('borrowers')
.where('Name',isEqualTo:NameController.text)
.snapshots()
.isEmpty
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文