whole filtering operation works fine except for ‘sellerDetails.selectedHoursByDay’. I cannot reach out to the child values of selectedHoursByDay. DaysFilter is an array that contains the name of the days.
void applyFilter() async{
Query<Map<String, dynamic>> filterquery = _firestore.collection('Users');
if (nameFilter != null && nameFilter!.isNotEmpty) {
filterquery = filterquery.where('sellerDetails.sellerName', isEqualTo: nameFilter);
}
if (cityFilter != null && cityFilter!.isNotEmpty) {
filterquery = filterquery.where('sellerDetails.city', isEqualTo: cityFilter);
}
if (districtFilter != null && districtFilter!.isNotEmpty) {
filterquery = filterquery.where('sellerDetails.district', isEqualTo: districtFilter);
}
if (daysFilter != null && daysFilter!.isNotEmpty) {
filterquery = filterquery.where('sellerDetails.selectedHoursByDay', arrayContainsAny: daysFilter);
}
setState(() {
_userStream = filterquery.snapshots();
});
}
I wanted to get the days from firestore and check if it matches any day in the daysFilter array
2
Answers
I mananged to solve it after two weeks later. I should had think more simpler, basically added the days into a seperate list and inserted that array to the database for the filtering.
sellerDetails.selectedHoursByDay
isn’t an array at all. It’s a object that contains other nested fields that are arrays. For example, your screenshot shows two different arrays each calledsellerDetails.selectedHoursByDay.Cuma
andsellerDetails.selectedHoursByDay.Cumartesi
.Since it’s not an array, an array filter will never work with that field. And you can’t use a filter that works across multiple different arrays in a document. Perhaps you need to restructure or add new data that supports the kind of filter you want to apply on those arrays.