feat: Add functionality to move inventory items to pantry and enhance pantry management
Test Suite / test (24.15.0) (push) Has been cancelled

- Implemented moveInventoryItemToPantry method in InventoryRepository to facilitate moving items from inventory to pantry.
- Enhanced InventoryScreen with a new header section providing context about the inventory.
- Added a button in SwipeableInventoryTile to move items to pantry with appropriate error handling.
- Introduced movePantryItemToInventory method in PantryRepository to support moving items back to inventory.
- Refactored PantryScreen to rename _addToInventory to _moveToInventory for clarity and updated UI to reflect changes.
- Added AdminPantryItem model to represent pantry items in the admin panel.
- Created AdminPantryPanel for managing pantry items, including moving items to inventory and listing users.
- Developed AdminPrivateProductsPanel for managing private products, allowing promotion to global products.
This commit is contained in:
Nils-Johan Gynther
2026-05-11 09:06:30 +02:00
parent edf9c74e75
commit 84ccabe2fe
27 changed files with 1851 additions and 376 deletions
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../core/api/api_error_mapper.dart';
import '../../admin/data/admin_repository.dart';
import '../../admin/domain/receipt_alias.dart';
@@ -39,7 +40,7 @@ class _UserAliasesScreenState extends ConsumerState<UserAliasesScreen> {
});
} catch (e) {
if (!mounted) return;
setState(() => _error = 'Kunde inte ladda alias: $e');
setState(() => _error = mapErrorToUserMessage(e, context));
} finally {
if (mounted) setState(() => _isLoading = false);
}
@@ -95,87 +96,148 @@ class _UserAliasesScreenState extends ConsumerState<UserAliasesScreen> {
body: Builder(builder: (_) {
if (_isLoading) return const Center(child: CircularProgressIndicator());
if (_error != null) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(_error!, style: TextStyle(color: theme.colorScheme.error)),
const SizedBox(height: 12),
FilledButton(onPressed: _load, child: const Text('Försök igen')),
],
),
return buildCopyableErrorPanel(
context: context,
message: _error!,
onRetry: _load,
title: 'Kunde inte läsa alias',
);
}
if (_aliases.isEmpty) {
return Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.link_off_outlined, size: 48, color: theme.colorScheme.outlineVariant),
const SizedBox(height: 16),
Text(
'Inga alias sparade ännu.',
style: theme.textTheme.bodyLarge,
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
'Alias skapas när du väljer att lära in dem under kvittoimporten.',
style: theme.textTheme.bodySmall?.copyWith(color: theme.colorScheme.onSurfaceVariant),
textAlign: TextAlign.center,
),
],
),
),
);
}
return ListView.separated(
padding: const EdgeInsets.all(16),
itemCount: _aliases.length,
separatorBuilder: (_, __) => const Divider(height: 1),
itemBuilder: (ctx, i) {
final alias = _aliases[i];
return ListTile(
leading: Icon(
alias.isGlobal ? Icons.public_outlined : Icons.link_outlined,
color: theme.colorScheme.primary,
),
title: Text(
alias.receiptName,
style: theme.textTheme.bodyMedium?.copyWith(fontWeight: FontWeight.w500),
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'${alias.displayProductName}',
style: theme.textTheme.bodySmall,
),
const SizedBox(height: 4),
Wrap(
spacing: 8,
return ListView(
padding: const EdgeInsets.all(16),
children: [
Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Chip(
visualDensity: VisualDensity.compact,
label: Text(alias.isGlobal ? 'Global fallback' : 'Privat alias'),
Text('Aliasöversikt', style: theme.textTheme.titleMedium),
const SizedBox(height: 8),
Text(
'Privata alias gäller bara dig. Globala alias används som fallback i receipt-importen och skapas av admin.',
style: theme.textTheme.bodyMedium,
),
const SizedBox(height: 8),
const Wrap(
spacing: 8,
runSpacing: 8,
children: [
Chip(label: Text('Privat alias')),
Chip(label: Text('Global fallback')),
Chip(label: Text('Receipt-import')),
],
),
],
),
],
),
),
trailing: alias.isPrivate
? IconButton(
icon: const Icon(Icons.delete_outline),
tooltip: 'Ta bort alias',
color: theme.colorScheme.error,
onPressed: () => _delete(alias),
)
: null,
);
},
const SizedBox(height: 16),
Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.link_off_outlined, size: 48, color: theme.colorScheme.outlineVariant),
const SizedBox(height: 16),
Text(
'Inga alias sparade ännu.',
style: theme.textTheme.bodyLarge,
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
'Alias skapas när du väljer att lära in dem under kvittoimporten.',
style: theme.textTheme.bodySmall?.copyWith(color: theme.colorScheme.onSurfaceVariant),
textAlign: TextAlign.center,
),
],
),
),
),
],
);
}
return ListView(
padding: const EdgeInsets.all(16),
children: [
Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Aliasöversikt', style: theme.textTheme.titleMedium),
const SizedBox(height: 8),
Text(
'Privata alias gäller bara dig. Globala alias används som fallback i receipt-importen och skapas av admin.',
style: theme.textTheme.bodyMedium,
),
const SizedBox(height: 8),
const Wrap(
spacing: 8,
runSpacing: 8,
children: [
Chip(label: Text('Privat alias')),
Chip(label: Text('Global fallback')),
Chip(label: Text('Receipt-import')),
],
),
],
),
),
),
const SizedBox(height: 16),
ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: _aliases.length,
separatorBuilder: (_, __) => const Divider(height: 1),
itemBuilder: (ctx, i) {
final alias = _aliases[i];
return ListTile(
leading: Icon(
alias.isGlobal ? Icons.public_outlined : Icons.link_outlined,
color: theme.colorScheme.primary,
),
title: Text(
alias.receiptName,
style: theme.textTheme.bodyMedium?.copyWith(fontWeight: FontWeight.w500),
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'${alias.displayProductName}',
style: theme.textTheme.bodySmall,
),
const SizedBox(height: 4),
Wrap(
spacing: 8,
children: [
Chip(
visualDensity: VisualDensity.compact,
label: Text(alias.isGlobal ? 'Global fallback' : 'Privat alias'),
),
],
),
],
),
trailing: alias.isPrivate
? IconButton(
icon: const Icon(Icons.delete_outline),
tooltip: 'Ta bort alias',
color: theme.colorScheme.error,
onPressed: () => _delete(alias),
)
: null,
);
},
),
],
);
}),
);