Home > Net >  List<dynamic> to List<LatLng> in flutter
List<dynamic> to List<LatLng> in flutter

Time:06-24

I'm pretty new at Flutter dev.

I got a very simple issue. I want to map a List<dynamic> to a List<LatLng> with this

var latLngCoordinates = coordinates.map((coord) => LatLng(coord[0], coord[1])).toList();

If I debug the code I got a List<dynamic> where each entry is LatLng object. How can I get a List<LatLng> instead of a List<dynamic> one for latLngCoordinates?

Thanks, FB

CodePudding user response:

You need to specify the type <LatLng> to the map function:

var latLngCoordinates = coordinates.map<LatLng>((coord) => LatLng(coord[0], coord[1])).toList();
  • Related