feat: enhance navigation by adding recipe links in inventory and pantry screens

This commit is contained in:
Nils-Johan Gynther
2026-04-24 14:13:26 +02:00
parent a39640d4ea
commit 13a0ab3584
7 changed files with 42 additions and 10 deletions
@@ -83,7 +83,7 @@ class _RecipeImportTabState extends ConsumerState<RecipeImportTab> {
context.push('/recipes/create', extra: <String, dynamic>{ context.push('/recipes/create', extra: <String, dynamic>{
'markdown': result.markdown, 'markdown': result.markdown,
'imageUrl': result.imageUrl, 'imageUrl': result.imageUrl,
}); }).then((_) => context.go('/recipes'));
} catch (e) { } catch (e) {
if (!mounted) return; if (!mounted) return;
setState(() => _error = mapErrorToUserMessage(e, context)); setState(() => _error = mapErrorToUserMessage(e, context));
@@ -47,7 +47,7 @@ class _ConsumeInventoryScreenState
); );
ref.invalidate(inventoryDetailProvider(widget.itemId)); ref.invalidate(inventoryDetailProvider(widget.itemId));
ref.invalidate(inventoryProvider); ref.invalidate(inventoryProvider);
if (mounted) context.pop(); if (mounted) context.go('/inventory');
} catch (e) { } catch (e) {
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context) ScaffoldMessenger.of(context)
@@ -119,11 +119,22 @@ class InventoryScreen extends ConsumerWidget {
Positioned( Positioned(
right: 16, right: 16,
bottom: 16, bottom: 16,
child: FloatingActionButton.extended( child: Column(
mainAxisSize: MainAxisSize.min,
children: [
FloatingActionButton.extended(
onPressed: () => context.push('/inventory/create'), onPressed: () => context.push('/inventory/create'),
icon: const Icon(Icons.add), icon: const Icon(Icons.add),
label: const Text('Lägg till'), label: const Text('Lägg till'),
), ),
const SizedBox(height: 8),
FloatingActionButton.extended(
onPressed: () => context.go('/recipes'),
icon: const Icon(Icons.restaurant_menu),
label: const Text('Recept'),
),
],
),
), ),
], ],
); );
@@ -129,6 +129,11 @@ class _MealPlanScreenState extends ConsumerState<MealPlanScreen> {
onPressed: () => ref.read(mealPlanWeekOffsetProvider.notifier).reset(), onPressed: () => ref.read(mealPlanWeekOffsetProvider.notifier).reset(),
child: Text(l10n.mealPlanWeekCurrent), child: Text(l10n.mealPlanWeekCurrent),
), ),
IconButton(
tooltip: 'Gå till recept',
icon: const Icon(Icons.restaurant_menu),
onPressed: () => context.go('/recipes'),
),
], ],
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
@@ -283,11 +283,21 @@ class _PantryScreenState extends ConsumerState<PantryScreen> {
return ListView( return ListView(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Text(
'Produkter du alltid räknar med att ha hemma.', 'Produkter du alltid räknar med att ha hemma.',
style: Theme.of(context).textTheme.bodyMedium, style: Theme.of(context).textTheme.bodyMedium,
), ),
IconButton(
tooltip: 'Gå till recept',
icon: const Icon(Icons.restaurant_menu),
onPressed: () => context.go('/recipes'),
),
],
),
const SizedBox(height: 12), const SizedBox(height: 12),
Row( Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@@ -36,6 +36,11 @@ class RecipeDetailScreen extends ConsumerWidget {
onPressed: () => onPressed: () =>
context.push('/recipes/$recipeId/edit'), context.push('/recipes/$recipeId/edit'),
), ),
IconButton(
tooltip: 'Gå till inventarie',
icon: const Icon(Icons.inventory_2_outlined),
onPressed: () => context.go('/inventory'),
),
_DeleteButton(recipe: recipeAsync.value!), _DeleteButton(recipe: recipeAsync.value!),
], ],
), ),
@@ -46,6 +51,7 @@ class RecipeDetailScreen extends ConsumerWidget {
onRetry: () => ref.invalidate(recipeDetailProvider(recipeId)), onRetry: () => ref.invalidate(recipeDetailProvider(recipeId)),
), ),
data: (recipe) => CustomScrollView( data: (recipe) => CustomScrollView(
physics: const BouncingScrollPhysics(),
slivers: [ slivers: [
SliverAppBar( SliverAppBar(
expandedHeight: MediaQuery.of(context).size.height * 2 / 3, expandedHeight: MediaQuery.of(context).size.height * 2 / 3,
@@ -218,7 +218,7 @@ class _RecipeEditScreenState extends ConsumerState<RecipeEditScreen> {
); );
ref.invalidate(recipeDetailProvider(widget.recipeId)); ref.invalidate(recipeDetailProvider(widget.recipeId));
ref.invalidate(recipesProvider); ref.invalidate(recipesProvider);
if (mounted) context.pop(); if (mounted) context.go('/recipes/${widget.recipeId}');
} on ApiException catch (e) { } on ApiException catch (e) {
if (e.type == ApiErrorType.unauthorized) { if (e.type == ApiErrorType.unauthorized) {
await ref.read(authStateProvider.notifier).logout(); await ref.read(authStateProvider.notifier).logout();