parser logic added

This commit is contained in:
davmar
2026-08-30 12:24:29 +02:00
parent 35d5c90d81
commit 3b698a3667
28 changed files with 3018 additions and 346 deletions
+8
View File
@@ -8,20 +8,27 @@ class LineItem {
required this.price,
this.quantity,
this.unitPrice,
this.discount = 0,
});
final String id;
final String name;
/// Line total after any discount.
final double price;
final int? quantity;
final double? unitPrice;
/// Negative amount when a discount was folded into [price].
final double discount;
LineItem copyWith({
String? id,
String? name,
double? price,
int? quantity,
double? unitPrice,
double? discount,
bool clearQuantity = false,
}) {
return LineItem(
@@ -30,6 +37,7 @@ class LineItem {
price: price ?? this.price,
quantity: clearQuantity ? null : (quantity ?? this.quantity),
unitPrice: clearQuantity ? null : (unitPrice ?? this.unitPrice),
discount: discount ?? this.discount,
);
}
}
+57
View File
@@ -0,0 +1,57 @@
/// A named list of things to buy.
library;
class ShoppingList {
const ShoppingList({
required this.id,
required this.name,
required this.itemCount,
required this.checkedCount,
required this.updatedAt,
});
final int id;
final String name;
final int itemCount;
final int checkedCount;
final DateTime updatedAt;
factory ShoppingList.fromMap(Map<String, Object?> map) {
return ShoppingList(
id: map['id']! as int,
name: map['name']! as String,
itemCount: (map['item_count'] as num?)?.toInt() ?? 0,
checkedCount: (map['checked_count'] as num?)?.toInt() ?? 0,
updatedAt: DateTime.parse(map['updated_at']! as String),
);
}
}
class ShoppingListItem {
const ShoppingListItem({
required this.id,
required this.listId,
required this.name,
required this.checked,
required this.sortOrder,
this.productId,
});
final int id;
final int listId;
final String name;
final bool checked;
final int sortOrder;
final int? productId;
factory ShoppingListItem.fromMap(Map<String, Object?> map) {
return ShoppingListItem(
id: map['id']! as int,
listId: map['list_id']! as int,
name: map['name']! as String,
checked: (map['checked'] as int? ?? 0) == 1,
sortOrder: (map['sort_order'] as num?)?.toInt() ?? 0,
productId: map['product_id'] as int?,
);
}
}