/// One time a product was bought, used for price and purchase history. library; class Purchase { const Purchase({ required this.shopId, required this.boughtAt, required this.supermarket, required this.price, this.quantity, this.unitPrice, this.receiptImagePath, }); final int shopId; final DateTime boughtAt; final String supermarket; final double price; final int? quantity; final double? unitPrice; final String? receiptImagePath; double get unitOrLinePrice => unitPrice ?? price; factory Purchase.fromMap(Map map) { return Purchase( shopId: map['shop_id']! as int, boughtAt: DateTime.parse(map['shopped_at']! as String), supermarket: map['supermarket']! as String, price: (map['price']! as num).toDouble(), quantity: map['quantity'] as int?, unitPrice: (map['unit_price'] as num?)?.toDouble(), receiptImagePath: map['receipt_image_path'] as String?, ); } }