-1

im using streambuilder, and i want the data 'order by' and 'where' at the same time. cause everytime im using both of the query my list doesn'show up, but when im using only 1 query the list show up

here my streambuilder

StreamBuilder<QuerySnapshot>(
                          stream: FirebaseFirestore.instance.collection("clothes")
                              .where('clothesCloset',
                                  isEqualTo: closet.closetId)
                              .snapshots(),
                          builder: (BuildContext context,
                              AsyncSnapshot<QuerySnapshot> snapshot) {
                            if (snapshot.hasError) {
                              return Text("Failed to load data!");
                            }
                            switch (snapshot.connectionState) {
                              case ConnectionState.waiting:
                                return ActivityServices.loadings();
                              default:
                                return new GridView(
                                  gridDelegate:
                                      SliverGridDelegateWithFixedCrossAxisCount(
                                    crossAxisCount: 2, //two columns
                                    mainAxisSpacing: 0.1, //space the card
                                    childAspectRatio: 0.800,
                                  ),
                                  children: snapshot.data.docs
                                      .map((DocumentSnapshot doc) {
                                    Clothes clothes;
                                    clothes = new Clothes(
                                      doc.data()['clothesId'],
                                      doc.data()['clothesName'],
                                      doc.data()['clothesDesc'],
                                      doc.data()['clothesImage'],
                                      doc.data()['clothesCloset'],
                                      doc.data()['clothesAddBy'],
                                      doc.data()['clothesAge'],
                                      doc.data()['clothesTag'],
                                      doc.data()['clothesStatus'],
                                      doc.data()['clothesLaundry'],
                                      doc.data()['createdAt'],
                                      doc.data()['updatedAt'],
                                    );
                                    return CardClothesLemari(clothes: clothes);
                                  }).toList(),
                                );
                            }
                          },
                        )

1 Answers1

1

Check your console output when you run the program. There should be a line that asks you to create an index for compound queries. The error message will contain a direct link to do the same.

Zac
  • 998
  • 6
  • 19
  • 1
    Just complementing this answer, here's the official doc for this https://firebase.google.com/docs/firestore/query-data/index-overview#queries_supported_by_composite_indexes – Puteri Aug 24 '21 at 01:14