Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert List of String to List of int Dart

Tags:

dart

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>'
like image 330
TSR Avatar asked Mar 21 '19 05:03

TSR


1 Answers

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.

like image 181
hellopeach Avatar answered Oct 21 '22 12:10

hellopeach