简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM