Mario
 · Developer

Filters on Google Maps query

Troubleshooting

Hi communuty!

i'm facing new issues with Google Maps widget. The point is, Google Maps can only show the 'Document type' (not LatLng array) results from a 'Backend Query'. I can't query on an 'Action' and then load the result (Output Action) on the Map. If i do that, it shows an error. It even load the App.

In my firebase Database i have a list of documents that every doc contains a List<Int> field named 'rental_days'. This field contains for example something like [1,2,3] or [6,7].

I need to make a collection query and filter if the field 'rental_days' of every doc contains for example '[1,2,3]' or '[6,7]', but the filter options only allow me to check if 'Array Contains' or 'Array Contains Any'. I would need to check if the 'rental_days' field contains 'all' numbers from the user input.

For example:

Let's supose in firebase Database Doc List:

Doc1.rental_days = [1,2,3,4];

Doc2.rental_days = [6,7];

Doc3.rental_days = [4,5];

Then supose i need to query and filter only the docs that in 'rental_days' contains a '6' and a '7' ( [6,7] ).

I tried to write a custom action to filter the query, but as i said, the Google Maps Widget only allow to create multiple Document markers from a Query Collection (not from Action Result). Also i can't use LatLng markers because i need to listen to 'On Marker Tap' event and show the info from the Firebase Doc.

Do you know how to solve this??

Thanks

What have you tried so far?

I've tried to create custom Actions and Custom Functions to filter the results with some code like:

List<CarsRecord>? mapCarSearch(
  List<CarsRecord> carList, //Results from Firebase Query
  List<int> numbersToCheck,
) {
  /// MODIFY CODE ONLY BELOW THIS LINE

  List<CarsRecord> checkRentalDays(List<CarsRecord> carRecords) {
    
    List<CarsRecord> carsFoundList = [];

    
    for (var carRecord in carRecords) {
      bool allNumbersPresent = numbersToCheck
          .every((number) => carRecord.carRentalDays.contains(number));
      if (allNumbersPresent) {
        carsFoundList.add(carRecord);
      }
    }

    return carsFoundList;
  }
}

But if i select the 'Output result' from the previous code as a 'Marker Documents' in Google Maps Widget i get an error at compilation.

Did you check FlutterFlow's Documentation for this topic?
Yes