How to filter the query for firestore in flutter?

Viewed 232

I am trying to implement a search filter for the firestore database list in flutter,widget.selectedValue is the value of the category to filter with it is received from another StatefulWidget successfully but does not change the query, and hence the results are not received as desired. the below method getquery() is called in initState(), but it doesn't work, How should I make sure when the below method is called in initState() it changes the query as required

getquery(){String category = widget.selectedValue;

    if (category != null){

      query = widget._firestore.collection("items").where("itemcategory", isEqualTo: category ).orderBy('timestamp', descending: true);   }
    else {
       query = widget._firestore.collection("items").orderBy('timestamp', descending: true);

    }

}
0 Answers
Related