【问题标题】:E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: type 'String' is not a subtype of type 'int'E/flutter:[错误:flutter/lib/ui/ui_dart_state.cc(199)] 未处理的异常:“String”类型不是“int”类型的子类型
【发布时间】:2021-07-24 08:18:14
【问题描述】:

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

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

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    替换

    element.data()["price"],
    

    收件人:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-23
      • 1970-01-01
      • 2020-10-03
      • 2020-05-09
      • 1970-01-01
      • 2021-03-22
      • 2020-04-19
      相关资源
      最近更新 更多