feat: add Flutter quality checks and tests for category chips in inventory and pantry screens
This commit is contained in:
@@ -24,13 +24,14 @@ class PantryScreen extends ConsumerStatefulWidget {
|
||||
|
||||
class _PantryScreenState extends ConsumerState<PantryScreen> {
|
||||
static const _locationOptions = <String>['', 'Kyl', 'Frys', 'Skafferi'];
|
||||
static const _sortByDisplayedCategory = 'l1CategoryAsc';
|
||||
String _locationFilter = '';
|
||||
String _sort = 'nameAsc';
|
||||
|
||||
List<({String value, String label})> _sortOptions() => const [
|
||||
(value: 'nameAsc', label: 'Namn (A-O)'),
|
||||
(value: 'nameDesc', label: 'Namn (O-A)'),
|
||||
(value: 'l1CategoryAsc', label: 'L1-kategori (A-O)'),
|
||||
(value: _sortByDisplayedCategory, label: 'Kategori (A-O)'),
|
||||
(value: 'locationAsc', label: 'Plats (A-O)'),
|
||||
];
|
||||
|
||||
@@ -172,7 +173,7 @@ class _PantryScreenState extends ConsumerState<PantryScreen> {
|
||||
SnackBar(content: Text('Flyttade "${item.displayName}" till inventarie.')),
|
||||
);
|
||||
} catch (error) {
|
||||
_logger.severe('Failed to add item to inventory: $error');
|
||||
_logger.severe('Failed to add item to inventory');
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
buildCopyableErrorSnackBar(context, mapErrorToUserMessage(error, context)),
|
||||
@@ -206,7 +207,7 @@ class _PantryScreenState extends ConsumerState<PantryScreen> {
|
||||
await ref.read(pantryRepositoryProvider).deletePantryItem(item.id, token: token);
|
||||
ref.invalidate(pantryProvider);
|
||||
} catch (error) {
|
||||
_logger.severe('Failed to remove pantry item: $error');
|
||||
_logger.severe('Failed to remove pantry item');
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
buildCopyableErrorSnackBar(context, mapErrorToUserMessage(error, context)),
|
||||
@@ -231,7 +232,7 @@ class _PantryScreenState extends ConsumerState<PantryScreen> {
|
||||
|
||||
if (pantryAsync.hasError) {
|
||||
final error = pantryAsync.error;
|
||||
_logger.severe('Error loading pantry or products: $error');
|
||||
_logger.severe('Error loading pantry or products');
|
||||
return buildCopyableErrorPanel(
|
||||
context: context,
|
||||
message: mapErrorToUserMessage(error ?? 'Okänt fel', context),
|
||||
@@ -250,9 +251,12 @@ class _PantryScreenState extends ConsumerState<PantryScreen> {
|
||||
return (item.location ?? '').trim() == _locationFilter;
|
||||
}).toList();
|
||||
|
||||
final l1LowerByItemId = {
|
||||
final displayedCategoryLowerByItemId = {
|
||||
for (final item in filteredItems)
|
||||
item.id: _resolveL1Category(item).toLowerCase(),
|
||||
item.id: categoryChipText(
|
||||
categoryPath: item.categoryPath,
|
||||
fallbackL1: _resolveL1Category(item),
|
||||
).label.toLowerCase(),
|
||||
};
|
||||
|
||||
filteredItems.sort((a, b) {
|
||||
@@ -266,9 +270,11 @@ class _PantryScreenState extends ConsumerState<PantryScreen> {
|
||||
if (byLocation != 0) return byLocation;
|
||||
return a.displayName.toLowerCase().compareTo(b.displayName.toLowerCase());
|
||||
}
|
||||
if (_sort == 'l1CategoryAsc') {
|
||||
final byL1 = (l1LowerByItemId[a.id] ?? '').compareTo(l1LowerByItemId[b.id] ?? '');
|
||||
if (byL1 != 0) return byL1;
|
||||
if (_sort == _sortByDisplayedCategory) {
|
||||
final byCategory = (displayedCategoryLowerByItemId[a.id] ?? '').compareTo(
|
||||
displayedCategoryLowerByItemId[b.id] ?? '',
|
||||
);
|
||||
if (byCategory != 0) return byCategory;
|
||||
return a.displayName.toLowerCase().compareTo(b.displayName.toLowerCase());
|
||||
}
|
||||
return a.displayName.toLowerCase().compareTo(b.displayName.toLowerCase());
|
||||
|
||||
Reference in New Issue
Block a user