class ShoppingItem { final String name; final String category; final double amount; final String unit; final bool checked; final double inStock; const ShoppingItem({ required this.name, required this.category, required this.amount, required this.unit, required this.checked, required this.inStock, }); factory ShoppingItem.fromJson(Map json) { return ShoppingItem( name: json['name'] as String? ?? '', category: json['category'] as String? ?? 'other', amount: (json['amount'] as num?)?.toDouble() ?? 0, unit: json['unit'] as String? ?? '', checked: json['checked'] as bool? ?? false, inStock: (json['in_stock'] as num?)?.toDouble() ?? 0, ); } Map toJson() => { 'name': name, 'category': category, 'amount': amount, 'unit': unit, 'checked': checked, 'in_stock': inStock, }; ShoppingItem copyWith({bool? checked}) => ShoppingItem( name: name, category: category, amount: amount, unit: unit, checked: checked ?? this.checked, inStock: inStock, ); }