Reputation: 368
String map = widget.list[widget.index]['map'];
example for "[LatLng(12.82879876203614, 80.12908793985844),LatLng(12.83370395257544, 80.1245865225792),LatLng(12.839642030904889, 80.12061484158039),]"
the data of map is now string but I want LatLng format ( without "" Double Quotation ) like [LatLng(12.82879876203614, 80.12908793985844),LatLng(12.83370395257544, 80.1245865225792),LatLng(12.839642030904889, 80.12061484158039),]
Set<Polygon> polygonSet = new Set();
polygonSet.add(Polygon(
polygonId: PolygonId('test'),
points: map,
strokeWidth: 2,
strokeColor: Colors.blue,
fillColor: Colors.blue.withOpacity(0.4),));
return polygonSet;
}
the out put error: type 'String' is not a subtype of type 'LatLng'
Upvotes: 0
Views: 569
Reputation: 971
You can use jsonDecode() to convert the String to List of LatLng.
import 'dart:convert';
void main() {
String map =
'"[LatLng(12.82879876203614, 80.12908793985844),LatLng(12.83370395257544, 80.1245865225792),LatLng(12.839642030904889, 80.12061484158039),]"';
List<LatLng> latlngList = jsonDecode(map);
print(latlngList);
}
And the output will be :
[LatLng(12.82879876203614, 80.12908793985844),LatLng(12.83370395257544, 80.1245865225792),LatLng(12.839642030904889, 80.12061484158039),]
Upvotes: 0