58 lines
1.4 KiB
Dart
58 lines
1.4 KiB
Dart
/// 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?,
|
|
);
|
|
}
|
|
}
|