

I have one Json structure with three maps, one is list of products then total and tax. I have to parse this json structure in flutter. I created on model class. Now i am getting the error in type casting.
How to solve this?
JSON Structure:
{
"products" : [
{
"cart_id": "7",
},
{
"cart_id": "7",
}
],
"total": 100,
"tax": 100
}
Model class :
class CartModel {
List<Product> produtcts;
double total;
CartModel({this.produtcts, this.total});
factory CartModel.fromJson(Map<String, dynamic> json) {
var list = json['products'] as List;
print(list.runtimeType);
List<Product> products = list.map((i) =>
Product.fromJson(i)).toList();
return CartModel(
produtcts: products, total: json['total'],);
}
}
class Product {
String cartId;
Product({this.cartId,});
factory Product.fromJson(Map<String, dynamic> json) {
return Product(
productId: json['cart_id'],
);
}
}
Product.fromJsonorCartModel.fromJson?