How to convert a list from one type to another without a for loop?
List <String> lstring = <String>["1", "2"];
List <int> lint = lstring.map(int.parse);
I get the error:
type 'MappedListIterable<String, int>' is not a subtype of type 'List<int>'
You need to add a toList() to the end of the second line.
List <String> lstring = <String>["1", "2"];
List <int> lint = lstring.map(int.parse).toList();
This will do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With