flutter - E/flutter:[错误:flutter/lib/ui/ui_dart_state.cc(199)] 未处理的异常:“String”类型不是“int”类型的子类型
问题描述
** 如何解决上述错误此错误导致以下代码.......................... ..................................................... ..................................................... ..................................................... ..................................................... ..................................................... ...... **
product.dart
Future<void> getHomeAchiveData() async {
List<Productss> newList = [];
QuerySnapshot featureSnapShot =
await FirebaseFirestore.instance.collection("homearchive").get();
featureSnapShot.docs.forEach(
(element) {
featureData = Productss(
image: element.data()["image"],
name: element.data()["name"],
price: element.data()["price"],
description: element.data()["description"]);
newList.add(featureData);
},
);
homeAchive = newList;
notifyListeners();
}
Future<void> getHomeAchiveData() async {
List<Productss> newList = [];
QuerySnapshot featureSnapShot =
await FirebaseFirestore.instance.collection("homearchive").get();
featureSnapShot.docs.forEach(
(element) {
featureData = Productss(
image: element.data()["image"],
name: element.data()["name"],
price: element.data()["price"],// error cause from this line**
description: element.data()["description"]);
newList.add(featureData);
},
);
homeAchive = newList;
notifyListeners();
}
Error in line
price: element.data()["price"],// error cause from this line**
类别模型.dart
categorymodel.dart
class Productss {
final String name;
final String image;
final String image2;
final String image3;
final String image4;
final String description;
final String shortInfo;
final int price;
final int count;
Productss( {this.count,this.shortInfo, this.image2, this.image3, this.image4,@required this.description,@required this.image, @required this.name, @required this.price});
}
解决方案
代替
element.data()["price"],
到:
int.parse(element.data()["price"],)
推荐阅读
- javascript - ReactJS _ NextJs - 我的 console.log 返回我:“onmozfullscreenchange 已弃用”
- c# - 使用 LINQ 将数据插入到使用序列作为主键生成器的表中
- css - 使用 CSS 旋转在相对层次结构中悬停不可靠
- python-3.x - Ubuntu“git pull --rebase”得到“无法统计对象”的错误 - 你能建议是什么问题吗
- redux - 我的减速器应该处理@@redux-saga-test-plan/INIT 操作吗?
- android - 一旦应用程序离线,React Native AsyncStorage 就会停止工作
- c# - 发布 POST 后在哪里可以添加 GET 方法?
- python - 使用 patch.Rectangle 绘制不规则光栅图时避免缓慢循环
- scala - 将 Scala 反射 MethodMirror 转换为 Scala 函数
- mysql - 基于加入条件的条件 INNER JOIN 或 LEFT JOIN