Below is how i am fetching my data

static Future<List<Item>> fetchItems(String query) async {
    try {
      final response = await http.get(
          Uri.parse(
              "https://api.json-generator.com/templates/ueOoUwh5r44G/data"),
          headers: {
            "Content-Type": "application/json",
            "Authorization": "Bearer tltsp6dmnbif01jy9xfo9ssn4620u89xhuwcm5t3",
          }) /*.timeout(const Duration(seconds: Config.responseTimeOutInSeconds))*/;

      final List<Item> itemsList;

      if (response.statusCode == 200) {
        itemsList = json
            .decode(response.body)
            .map<Item>((json) => Item.fromJson(json))
            .where((item) {
          final idLower = item.id.toLowerCase();
          final titleLower = item.title.toLowerCase();
          final subTitleLower = item.subTitle.toLowerCase();
          final searchLower = query.toLowerCase();

          return idLower.contains(searchLower) ||
              titleLower.contains(searchLower) ||
              subTitleLower.contains(searchLower);
        }).toList();
      } else if (response.statusCode == 401) {
        itemsList = [];
      } else {
        itemsList = [];
      }
      return itemsList;
    } catch (e) {
      if (kDebugMode) {
        Logger().wtf(
            "FetchItemsException $e \n\nResponseStatusCode ${statusCode!}");
      }

      rethrow;
    }
  }

The above code is when i am using a class of Item. The issues that i am having is i have switched to load and populate the data using List<HashMap<String, dynamic>> instead of Item class

The code above is working fine if i am using List but fails when i am using List<HashMap<String, dynamic>>

I am going to highlight the section that is failing. Below is how i was checking if the following variables idLower, titleLower, subTitleLower contains what is in the search query and return the Item. Below is the code of how i was doing that


 if (response.statusCode == 200) {
        itemsList = json
            .decode(response.body)
            .map<Item>((json) => Item.fromJson(json))
            .where((item) {
          final idLower = item.id.toLowerCase();
          final titleLower = item.title.toLowerCase();
          final subTitleLower = item.subTitle.toLowerCase();
          final searchLower = query.toLowerCase();

          return idLower.contains(searchLower) ||
              titleLower.contains(searchLower) ||
              subTitleLower.contains(searchLower);
        }).toList();
      }

Below is how i am fetching using List<HashMap<String, dynamic>>


static Future<List<HashMap<String, dynamic>>> fetchLists(
      String url, String query) async {
    try {
      final response = await http.get(Uri.parse(url), headers: {
        "Content-Type": "application/json",
        "Authorization": "Bearer tltsp6dmnbif01jy9xfo9ssn4620u89xhuwcm5t3",
      }).timeout(const Duration(seconds: Config.responseTimeOutInSeconds));

      statusCode = response.statusCode;

      final List<HashMap<String, dynamic>> responseList;

      if (response.statusCode == 200) {
        responseList = json
            .decode(response.body)
            .map<HashMap<String, dynamic>>(
                (e) => HashMap<String, dynamic>.from(e))
            .where((mapItem) {
          final idLower = mapItem["id"].toLowerCase();
          final titleLower = mapItem["title"].toLowerCase();
          final subTitleLower = mapItem["subTitle"].subTitle.toLowerCase();
          final searchLower = query.toLowerCase();

          return idLower.contains(searchLower) ||
              titleLower.contains(searchLower) ||
              subTitleLower.contains(searchLower);
        }).toList();
      } else if (response.statusCode == 401) {
        responseList = [];
      } else {
        responseList = [];
      }

      return responseList;
    } catch (e) {
      if (kDebugMode) {
        Logger().wtf(
            "FetchUsersUsingListOfStringObjectHashMapException $e \n\nResponseStatusCode ${statusCode!}");
      }

      rethrow;
    }
  }

And below is how i have tried to check if the items in the HashMap is contained in the query but its not working


 if (response.statusCode == 200) {
        responseList = json
            .decode(response.body)
            .map<HashMap<String, dynamic>>(
                (e) => HashMap<String, dynamic>.from(e))
            .where((mapItem) {
          final idLower = mapItem["id"].toLowerCase();
          final titleLower = mapItem["title"].toLowerCase();
          final subTitleLower = mapItem["subTitle"].subTitle.toLowerCase();
          final searchLower = query.toLowerCase();

          return idLower.contains(searchLower) ||
              titleLower.contains(searchLower) ||
              subTitleLower.contains(searchLower);
        }).toList();
      }