feat: enhance inventory and pantry features with filtering, sorting, and error handling improvements
This commit is contained in:
@@ -8,6 +8,7 @@ import '../../auth/data/auth_providers.dart';
|
||||
import '../../../core/ui/async_state_views.dart';
|
||||
import '../data/pantry_providers.dart';
|
||||
import '../domain/pantry_item.dart';
|
||||
import '../domain/pantry_product.dart';
|
||||
|
||||
class PantryScreen extends ConsumerStatefulWidget {
|
||||
const PantryScreen({super.key});
|
||||
@@ -219,6 +220,19 @@ class _PantryScreenState extends ConsumerState<PantryScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
String _resolveCategory(PantryItem item, Map<int, PantryProduct> productById) {
|
||||
final fromTree = productById[item.productId]?.categoryPath;
|
||||
if (fromTree != null && fromTree.trim().isNotEmpty) {
|
||||
return fromTree;
|
||||
}
|
||||
|
||||
if (item.category != null && item.category!.trim().isNotEmpty) {
|
||||
return item.category!;
|
||||
}
|
||||
|
||||
return 'Ovrigt';
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final pantryAsync = ref.watch(pantryProvider);
|
||||
@@ -241,6 +255,7 @@ class _PantryScreenState extends ConsumerState<PantryScreen> {
|
||||
|
||||
final pantryItems = pantryAsync.valueOrNull ?? const [];
|
||||
final products = productsAsync.valueOrNull ?? const [];
|
||||
final productById = {for (final product in products) product.id: product};
|
||||
final pantryProductIds = pantryItems.map((e) => e.productId).toSet();
|
||||
final availableProducts = products
|
||||
.where((product) => !pantryProductIds.contains(product.id))
|
||||
@@ -252,9 +267,7 @@ class _PantryScreenState extends ConsumerState<PantryScreen> {
|
||||
|
||||
final grouped = <String, List<PantryItem>>{};
|
||||
for (final item in pantryItems) {
|
||||
final category = (item.category == null || item.category!.isEmpty)
|
||||
? 'Ovrigt'
|
||||
: item.category!;
|
||||
final category = _resolveCategory(item, productById);
|
||||
grouped.putIfAbsent(category, () => []).add(item);
|
||||
}
|
||||
final categories = grouped.keys.toList()
|
||||
|
||||
Reference in New Issue
Block a user