** 如何解决上面的错误这个错误导致下面的代码...................................... ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ...... **
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**
categorymodel.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});
}
答案 0 :(得分:1)
替换
element.data()["price"],
致:
int.parse(element.data()["price"],)