Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

String to double from a map in Dart

Ive tried to use double.parse, double.tryparse as well as trying to convert it to int but it keeps giving the error ‘type ‘int’ is not a subtype of type ‘String”, ive searched a few sites but all the solutions show to use parse.

final locData = Map<String, dynamic>.from(local);

var dubLat = locData['lat'];

var lat = double.tryParse(dubLat);

ive tried changing var to double nit still give the same error.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The .tryParse takes a string or even the parse method for this instance takes a string. But your data is actually integers therefore the error type int is not a subtype of type string. You should consider either storing them as ints or using the .toString method before parsing them.

var dubLat = locData[‘lat’]; // Here dublat is not actually a string but integer. Your map has dynamic as a second parameter it can take all data types and this particular datatype is int not string which .parse expects.

var lat = double.tryParse(dubLat.toString());

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading