Files
recipe-app/flutter/lib/features/pantry/domain/pantry_item.dart
T
Nils-Johan Gynther e7251fd94c
Test Suite / test (24.15.0) (push) Has been cancelled
feat: add location field to PantryItem model and update related functionality
Co-authored-by: Copilot <copilot@github.com>
2026-05-06 11:54:56 +02:00

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(),
);
}
}