我在firebase中有一个字段,我将数字存储在其中(可以是double
或int
(,
当我读取这个数字并将其分配给参数为double
的函数时,如下所示:
Function someFunction(double x)
{
//some content
}
无论值是int
还是double
,它在web上都可以正常工作,但当我在移动设备上尝试相同的代码时,它会给出一个类型错误,说int
不是double
的子类型。
所以我想知道,在这里发生的颤振手机和颤振网页之间的区别是什么。
factory Animal.fromFirestore(Map<String, dynamic> map) {
return Animal(
id: map['id'] as String,
name: map['name'] as String,
dateBorn: map['dateBorn'].toDate(),
gender: map['gender'] as String,
father: map['father'] as String,
mother: map['mother'] as String,
raceFather: map['raceFather'] as String,
raceMother: map['raceMother'] as String,
percentageFather: map['percentageFather'] as String,
percentageMother: map['percentageMother'] as String,
animalTypeProduction: map['animalTypeProduction'] as String,
animalStage: map['animalStage'] as String,
weightBorn: **double.parse('${map['weightBorn']}'),
weightWeaning: double.parse('${map['weightWeaning']}'),
weightYear: double.parse('${map['weightYear']}'),**
color1: map['color1'] as String,
color2: map['color2'] as String,
observations: map['observations'] as String,
type: map['type'] as String,
img: map['img'] as String,
);
}
同样的错误也发生在我身上,为了解决这个问题,我将firebase中的数字转换为字符串,然后转换为双精度,结果显示为无错误,double.parse('${map['${firebaseNum'}]}')