e7251fd94c
Test Suite / test (24.15.0) (push) Has been cancelled
Co-authored-by: Copilot <copilot@github.com>
39 lines
1.1 KiB
Dart
39 lines
1.1 KiB
Dart
class PantryItem {
|
|
final int id;
|
|
final int productId;
|
|
final String productName;
|
|
final String? canonicalName;
|
|
final String? category;
|
|
final int? categoryId;
|
|
final String? location;
|
|
|
|
const PantryItem({
|
|
required this.id,
|
|
required this.productId,
|
|
required this.productName,
|
|
this.canonicalName,
|
|
this.category,
|
|
this.categoryId,
|
|
this.location,
|
|
});
|
|
|
|
String get displayName {
|
|
if (canonicalName != null && canonicalName!.trim().isNotEmpty) {
|
|
return canonicalName!;
|
|
}
|
|
return productName;
|
|
}
|
|
|
|
factory PantryItem.fromJson(Map<String, dynamic> json) {
|
|
final product = json['product'] as Map<String, dynamic>? ?? {};
|
|
return PantryItem(
|
|
id: (json['id'] as num).toInt(),
|
|
productId: (json['productId'] as num).toInt(),
|
|
productName: (product['name'] ?? '').toString(),
|
|
canonicalName: product['canonicalName']?.toString(),
|
|
category: product['category']?.toString(),
|
|
categoryId: (product['categoryId'] as num?)?.toInt(),
|
|
location: json['location']?.toString(),
|
|
);
|
|
}
|
|
} |