Firestore查询在StreamBuilder内部获得弹力中的其他信息

发布于 2025-02-12 09:15:22 字数 1762 浏览 1 评论 0原文

我的代码有问题。如果语句,我仅在StreamBuilder中收到我的第一个查询的数据。我需要使用循环吗???

使用Listenstream,我将收到例如4个结果。结果中有2个具有“ kategorien” =“ keine'”字段中的值。我需要完成这两个字段,以在我的程序中显示来自if streambuilder IF语句中查询的结果。我希望我能解释一下我的目标。

问题是,我仅收到数据库中第一个条目的第一个“ kategorie”。

有人可以帮我吗?

这是我的代码:

StreamBuilder<QuerySnapshot>(
              stream: listenStream,
              builder: (context,snapshot){
                if (snapshot.hasError) {
                  return Text('Something went wrong');
                }

                if (snapshot.connectionState == ConnectionState.waiting) {
                  return Text("Loading");
                }

                return ListView.builder(
                  itemCount:snapshot.data?.docs.length,
                  itemBuilder: (context,index){
                    String? falscheKat = snapshot.data?.docs[index]['kategorie'].toString();
                    if(falscheKat=='Keine')
                      {
                        FirebaseFirestore.instance.collection('artikel').where('item', isEqualTo: snapshot.data?.docs[index]['item'].toString())
                            .get().then((value) {
                          neueKat = value.docs[0].get("item");

                        });
                      }
                    return ListTile(

                      title: Text(snapshot.data?.docs[index]['item']),
                      subtitle: Text(neueKat.toString()),
                    );
                  },
                );
              })

在这里我的Firestore查询Listenstream:

final Stream<QuerySnapshot> listenStream = FirebaseFirestore.instance
        .collection('listen1')
        .doc('zuhause')
        .collection('artikel').snapshots();

i have problems with my code. i receive only the data of my first query inside the streambuilder if statement. do i need to use a loop ???

With listenStream i receive for example 4 results. 2 of the results have the value in field 'kategorien' = 'Keine'. These 2 fields i need to complete to show in my programm with the results from the query inside the if statement of the streambuilder. i hope i explained a little to understand my targets.

The problem is, that i receive only the first 'kategorie' for the first entry in the database.

can someone help my please?

Here is my code:

StreamBuilder<QuerySnapshot>(
              stream: listenStream,
              builder: (context,snapshot){
                if (snapshot.hasError) {
                  return Text('Something went wrong');
                }

                if (snapshot.connectionState == ConnectionState.waiting) {
                  return Text("Loading");
                }

                return ListView.builder(
                  itemCount:snapshot.data?.docs.length,
                  itemBuilder: (context,index){
                    String? falscheKat = snapshot.data?.docs[index]['kategorie'].toString();
                    if(falscheKat=='Keine')
                      {
                        FirebaseFirestore.instance.collection('artikel').where('item', isEqualTo: snapshot.data?.docs[index]['item'].toString())
                            .get().then((value) {
                          neueKat = value.docs[0].get("item");

                        });
                      }
                    return ListTile(

                      title: Text(snapshot.data?.docs[index]['item']),
                      subtitle: Text(neueKat.toString()),
                    );
                  },
                );
              })

and here my Firestore query listenStream:

final Stream<QuerySnapshot> listenStream = FirebaseFirestore.instance
        .collection('listen1')
        .doc('zuhause')
        .collection('artikel').snapshots();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

独孤求败 2025-02-19 09:15:22

对于第二firestore查询,请使用另一个streambuilder

Use another StreamBuilder for the second Firestore query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文