我有要转换为对象列表的字符串列表。
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;
}
答案 0 :(得分:1)
您应该在 map
上使用 List<String>
,如下所示:
List<FooObject> foos = listOfString.map((s) => Foo(s)).toList();