我想将一个简单的地图转换为当前我拥有的列表{Jack: 23, Adam: 27, Katherin: 25}
并希望实现[{ Jack, 23 }, { Adam, 27 }, { Katherin, 25 }]
Here you can find an example, the key - using map.entries
class Person {
final String name;
final int age;
Person(this.name, this.age);
}
void test() {
final map = <String, int>{"Jack": 23, "Adam": 27, "Katherin": 25};
final list = map.entries.map((entry) => Person(entry.key, entry.value)).toList();
}
If you don't want to use Person class, you can use the package with tuple https://pub.dev/packages/tuple
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.