如何在颤振中将 List<String> 转换为 List<Object>

时间:2021-07-03 09:54:38

标签: flutter dart

我有要转换为对象列表的字符串列表。

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;
  }

1 个答案:

答案 0 :(得分:1)

您应该在 map 上使用 List<String>,如下所示:

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