Aakib Algohar
Aakib Algohar

Reputation: 43

E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: type 'String' is not a subtype of type 'int'

** How to solve above error this error cause below code ...................................................................................................................................................................................................................................................................................................... **

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

Upvotes: 0

Views: 2500

Answers (1)

yogender
yogender

Reputation: 252

Replace

element.data()["price"],

To:

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

Upvotes: 1

Related Questions