Home > other >  _typeerror (type 'int' is not a subtype of type 'double')
_typeerror (type 'int' is not a subtype of type 'double')

Time:06-05

here is the picture

Here is the code.i receive this type of error. can anyone solve this problem.

_getAllHotProducts() async {
    var hotProducts = await _productService.getHotProducts();
    var result = json.decode(hotProducts.body);
    result['data'].forEach((data) {
      var model = Product();
      model.id = data['id'];
      model.name = data['name'];
      model.photo = data['photo'];
      model.price = data['price'];
      model.discount = data['discount'];

      setState(() {
        _productList.add(model);
      });
    });
  }

CodePudding user response:

An idea would be to use num instead of int or double in this case.

or

model.price = (data['price']).toDouble();
  • Related