E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] 未处理的异常:“String”类型不是“int”类型的子类型

时间:2021-07-24 08:18:14

标签: flutter dart

** 如何解决上面的错误这个错误导致下面的代码...................................... ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ………………………………………………………………………………………………………………………………………………………… ...... **

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});
        }

1 个答案:

答案 0 :(得分:1)

替换

element.data()["price"],

致:

int.parse(element.data()["price"],)