romu2000
romu2000

Reputation: 17

firestore query inside of streambuilder for getting additional informations in flutter

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();

Upvotes: 0

Views: 412

Answers (1)

user18309290
user18309290

Reputation: 8340

Use another StreamBuilder for the second Firestore query.

Upvotes: 1

Related Questions