64 lines
1.5 KiB
Dart
64 lines
1.5 KiB
Dart
/// A confirmed shopping trip saved from a receipt.
|
|
library;
|
|
|
|
class Shop {
|
|
const Shop({
|
|
required this.id,
|
|
required this.supermarket,
|
|
required this.shoppedAt,
|
|
required this.total,
|
|
required this.itemCount,
|
|
this.receiptImagePath,
|
|
});
|
|
|
|
final int id;
|
|
final String supermarket;
|
|
final DateTime shoppedAt;
|
|
final double total;
|
|
final int itemCount;
|
|
final String? receiptImagePath;
|
|
|
|
factory Shop.fromMap(Map<String, Object?> map) {
|
|
return Shop(
|
|
id: map['id']! as int,
|
|
supermarket: map['supermarket']! as String,
|
|
shoppedAt: DateTime.parse(map['shopped_at']! as String),
|
|
total: (map['total']! as num).toDouble(),
|
|
itemCount: (map['item_count'] as num?)?.toInt() ?? 0,
|
|
receiptImagePath: map['receipt_image_path'] as String?,
|
|
);
|
|
}
|
|
}
|
|
|
|
class ShopItem {
|
|
const ShopItem({
|
|
required this.id,
|
|
required this.shopId,
|
|
required this.productId,
|
|
required this.name,
|
|
required this.price,
|
|
this.quantity,
|
|
this.unitPrice,
|
|
});
|
|
|
|
final int id;
|
|
final int shopId;
|
|
final int productId;
|
|
final String name;
|
|
final double price;
|
|
final int? quantity;
|
|
final double? unitPrice;
|
|
|
|
factory ShopItem.fromMap(Map<String, Object?> map) {
|
|
return ShopItem(
|
|
id: map['id']! as int,
|
|
shopId: map['shop_id']! as int,
|
|
productId: map['product_id']! as int,
|
|
name: map['name']! as String,
|
|
price: (map['price']! as num).toDouble(),
|
|
quantity: map['quantity'] as int?,
|
|
unitPrice: (map['unit_price'] as num?)?.toDouble(),
|
|
);
|
|
}
|
|
}
|