先修改model类
model/cartInfo.dart类增加是否选中的属性
修改provide
修改UI部分pages/cart_page/cart_item.dart
测试效果
出现问题的原因,应该是在购物车内持久化的数据,没有isCheck这个新增加的属性,所以就报错了我们需要先点进去一个商品,把持久化的购物车数据清空掉,再重新添加购物车的持久化数据
然后重新添加几个商品到购物车内
最终代码
model/cartInfo.dart
class CartInfoModel { String goodsId; String goodsName; int count; double price; String images; bool isCheck; CartInfoModel( {this.goodsId, this.goodsName, this.count, this.price, this.images, this.isCheck}); CartInfoModel.fromJson(Map<String, dynamic> json) { goodsId = json['goodsId']; goodsName = json['goodsName']; count = json['count']; price = json['price']; images = json['images']; isCheck = json['isCheck']; } Map<String, dynamic> toJson() { final Map<String, dynamic> data = new Map<String, dynamic>(); data['goodsId'] = this.goodsId; data['goodsName'] = this.goodsName; data['count'] = this.count; data['price'] = this.price; data['images'] = this.images; data['isCheck'] = this.isCheck; return data; } }