feat: add location field to PantryItem model and update related functionality
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -27,7 +27,7 @@ class PantryRepository {
|
||||
|
||||
Future<List<PantryProduct>> fetchProducts({String? token}) async {
|
||||
try {
|
||||
final data = await _api.getJson(ProductApiPaths.list, token: token);
|
||||
final data = await _api.getJson(ProductApiPaths.mine, token: token);
|
||||
final list = data as List<dynamic>;
|
||||
_logger.info('Fetched ${list.length} products');
|
||||
return list
|
||||
@@ -39,11 +39,19 @@ class PantryRepository {
|
||||
}
|
||||
}
|
||||
|
||||
Future<PantryItem> createPantryItem(int productId, {String? token}) async {
|
||||
Future<PantryItem> createPantryItem(
|
||||
int productId, {
|
||||
String? token,
|
||||
String? location,
|
||||
}) async {
|
||||
try {
|
||||
final data = await _api.postJson(
|
||||
PantryApiPaths.list,
|
||||
body: {'productId': productId},
|
||||
body: {
|
||||
'productId': productId,
|
||||
if (location != null && location.trim().isNotEmpty)
|
||||
'location': location.trim(),
|
||||
},
|
||||
token: token,
|
||||
);
|
||||
_logger.info('Created pantry item for product ID: $productId');
|
||||
|
||||
@@ -5,6 +5,7 @@ class PantryItem {
|
||||
final String? canonicalName;
|
||||
final String? category;
|
||||
final int? categoryId;
|
||||
final String? location;
|
||||
|
||||
const PantryItem({
|
||||
required this.id,
|
||||
@@ -13,6 +14,7 @@ class PantryItem {
|
||||
this.canonicalName,
|
||||
this.category,
|
||||
this.categoryId,
|
||||
this.location,
|
||||
});
|
||||
|
||||
String get displayName {
|
||||
@@ -31,6 +33,7 @@ class PantryItem {
|
||||
canonicalName: product['canonicalName']?.toString(),
|
||||
category: product['category']?.toString(),
|
||||
categoryId: (product['categoryId'] as num?)?.toInt(),
|
||||
location: json['location']?.toString(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -374,6 +374,9 @@ class _PantryScreenState extends ConsumerState<PantryScreen> {
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
child: ListTile(
|
||||
title: Text(item.displayName),
|
||||
subtitle: item.location == null || item.location!.trim().isEmpty
|
||||
? null
|
||||
: Text('Plats: ${item.location}'),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
|
||||
Reference in New Issue
Block a user