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