'How to Convert List<String> to List<Object> in flutter

I have list of string that I want to convert into list of object.

List<Warehouse> getWarehouseSuggestions(String query) {
    final warehouseList = warehouses.entries.toList();
    final locIds = warehouseList.map((e) => e.value.name);
    List<String> a = List.of(locIds).where((warehouse) {
      final warehouseLower = warehouse.toLowerCase();
      final queryLower = query.toLowerCase();

      return warehouseLower.contains(queryLower);
    }).toList();

    List<Warehouse> b = List<Warehouse>.filled(a.length, a);
    return b;
  }


Solution 1:[1]

You should use map on your List<String>, something like this:

List<Foo> foos = listOfString.map((s) => Foo(s)).toList();
// or
List<Foo> foos = listOfString.map(Foo).toList();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1