0

I am building flutter app and using firestore. would like to give the user the capability to do some filtering on the data. so he will be selecting some filters and providing values to specific fields to be matched with the stored data in the firestore. the only way I can think of is something like building a stream builder with a stram like the below then when the user select the filter I add the value to the variable, and if filter not selected, the variable value should be equal to "Any". how can I represent this "Any" with firestore? or is there a better solution than this?

StreamBuilder<QuerySnapshot>(
            stream: FirebaseFirestore.instance
                .collection('PropertiesCollection')
                .orderBy('Property_date', descending: true)
                .where('Property_license', isEqualTo: variable1)
                .where('Property_city', isEqualTo: variable2)
                .where('Property_service', isEqualTo: variable3)
                .snapshots(),
Mark Nugromentry
  • 195
  • 2
  • 10

1 Answers1

2

If you want to match any value for a field, then don't use a filter on that field at all. You will need to add the where clause conditionally in that case, checking first to see if you need it before adding it.

See also:

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Thank you. this is a solution but when I have many items that user can use as a filter, then the probabilites of different streams is very high. fo instance for only two filters, I need to prepare four levels of streams (no filters, filter 1, filer 2, filer 1+filter 2). – Mark Nugromentry Nov 28 '22 at 18:45
  • 1
    Yes, it will require some work on your end. There is nothing in the Firestore SDK that will make this job any easier. There is no matching value for "any". – Doug Stevenson Nov 28 '22 at 18:54