How to get double from firestore number format in flutter

Viewed 1962

I found some question to this issue but none of them were for flutter. Basically I'm saving double value data in firestore number format but when the number is rounded for example 130.00 it save it as an integer. Now how can I make it double when retrieving the data. I've got simple model class which populate the data from map but I'm struggling to make it double there

  factory Tool.fromMap(Map<String, dynamic> toolData) {
    if (toolData == null) {
      return null;
    }
    final double length = toolData['length']; //<-- how to make it double here
    final String name = toolData['name'];
    ...
    return Tool(
        length: length,
        name: name
        ...);
  }

The known approaches doesn't seems to work here like

toolData['length'].toDouble()

UPDATE

Actually it works.. It just doesn't show as an option in android studio

enter image description here

1 Answers

I think parse method of double class could be solution for this.

double.parse(toolData['length'].toString());
Related