skip to Main Content

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

Structure of the database

I wanted to get the days from firestore and check if it matches any day in the daysFilter array

2

Answers


  1. Chosen as BEST ANSWER

    enter image description here

    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.


  2. 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 called sellerDetails.selectedHoursByDay.Cuma and sellerDetails.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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search