Search inside the List<Map> in flutter dart?

Viewed 1012

I want to filter the List by searching in the search bar but it does not work.

for (var map in offersList) {
      if (map.containsKey("foodname")) {
        if (map["foodname"] == query) {
          setState(() {
            offersList.clear();
            offersList.add(map);
          });
        }
      }
    }
1 Answers

Use a forEach

    offersList.forEach((map){
      if (map.containsKey("foodname")) {
        if (map["foodname"] == query) {
          setState(() {
            offersList.clear();
            offersList.add(map);
          });
        }
      }
});
Related