I have list of coin objects, I want to cast the list to the map. How can I use id's as a Map key?
class Coin {
int id;
String groupID;
String symbol;
int coinOrder;
String fullName;
}
I have list of coin objects, I want to cast the list to the map. How can I use id's as a Map key?
class Coin {
int id;
String groupID;
String symbol;
int coinOrder;
String fullName;
}
There is a fromIterable constructor for Map class. You can use it to convert a list to a map.
Map<int, Coin> map = Map.fromIterable(list, key: (item) => item.id, value: (item) => item);