我发现了一些关于这个问题的问题,但没有一个是关于 flutter 的。基本上,我以 firestore 数字格式保存双值数据,但是当数字四舍五入时,例如 130.00,它会将其保存为整数。现在如何在检索数据时使其翻倍。我有一个简单的模型类,它从 map 中填充数据,但我正在努力让它在那里翻倍
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
...);
}
已知的方法在这里似乎不起作用
toolData['length'].toDouble()
更新
实际上它是有效的..它只是在 android studio 中没有显示为一个选项
最佳答案
我认为parse method of double类可以解决这个问题。
double.parse(toolData['length'].toString());
关于flutter - 如何在 flutter 中从 firestore 数字格式中获取双倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61158721/