feat: implement grid layout for recipes with column selection and improve pantry product picker
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -1,3 +1,12 @@
|
|||||||
|
# Senaste ändringar (2026-04-24)
|
||||||
|
|
||||||
|
**Arkitektur- och UX-förbättringar:**
|
||||||
|
- Grid-vy för recept: Kolumnval (2/4/6/8) via ikon i AppShell, med Riverpod-provider och SharedPreferences.
|
||||||
|
- RecipesScreen är nu body-only, ingen egen Scaffold/AppBar.
|
||||||
|
- AppShell visar grid-ikon endast på /recipes.
|
||||||
|
- Buggfix: Produktväljaren i pantry/inventarie (ProductPickerField) — bottenark implementeras.
|
||||||
|
- Kodkvalitet: Inga absoluta Windows-sökvägar.
|
||||||
|
- Dokumentation och next_steps uppdaterade.
|
||||||
# Flutter Frontend - User Guide
|
# Flutter Frontend - User Guide
|
||||||
|
|
||||||
This README describes how to use the Flutter frontend for Recipe App from a user and operator perspective.
|
This README describes how to use the Flutter frontend for Recipe App from a user and operator perspective.
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
import '../../features/auth/data/auth_providers.dart';
|
import '../../features/auth/data/auth_providers.dart';
|
||||||
|
import '../../features/recipes/data/recipes_grid_provider.dart';
|
||||||
|
|
||||||
const _adminDestination = _AppDestination(
|
const _adminDestination = _AppDestination(
|
||||||
path: '/admin',
|
path: '/admin',
|
||||||
@@ -94,10 +95,26 @@ class AppShell extends ConsumerWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final isRecipesRoute = location.startsWith('/recipes') &&
|
||||||
|
!location.startsWith('/recipes/');
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(selectedDestination.title),
|
title: Text(selectedDestination.title),
|
||||||
actions: [
|
actions: [
|
||||||
|
if (isRecipesRoute)
|
||||||
|
PopupMenuButton<int>(
|
||||||
|
icon: const Icon(Icons.grid_view),
|
||||||
|
tooltip: 'Välj antal kolumner',
|
||||||
|
onSelected: (columns) =>
|
||||||
|
ref.read(recipesGridProvider.notifier).setColumns(columns),
|
||||||
|
itemBuilder: (context) => const [
|
||||||
|
PopupMenuItem(value: 2, child: Text('2 kolumner')),
|
||||||
|
PopupMenuItem(value: 4, child: Text('4 kolumner')),
|
||||||
|
PopupMenuItem(value: 6, child: Text('6 kolumner')),
|
||||||
|
PopupMenuItem(value: 8, child: Text('8 kolumner')),
|
||||||
|
],
|
||||||
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: 'Logga ut',
|
tooltip: 'Logga ut',
|
||||||
icon: const Icon(Icons.logout),
|
icon: const Icon(Icons.logout),
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
const _prefsKey = 'recipes_grid_columns';
|
||||||
|
|
||||||
|
class RecipesGridNotifier extends AsyncNotifier<int> {
|
||||||
|
@override
|
||||||
|
Future<int> build() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
return prefs.getInt(_prefsKey) ?? 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setColumns(int columns) async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.setInt(_prefsKey, columns);
|
||||||
|
state = AsyncData(columns);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final recipesGridProvider =
|
||||||
|
AsyncNotifierProvider<RecipesGridNotifier, int>(RecipesGridNotifier.new);
|
||||||
@@ -1,104 +1,55 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
|
|
||||||
import '../../../core/api/api_error_mapper.dart';
|
import '../../../core/api/api_error_mapper.dart';
|
||||||
import '../../../core/ui/async_state_views.dart';
|
import '../../../core/ui/async_state_views.dart';
|
||||||
import '../data/recipe_providers.dart';
|
import '../data/recipe_providers.dart';
|
||||||
|
import '../data/recipes_grid_provider.dart';
|
||||||
|
|
||||||
class RecipesScreen extends ConsumerStatefulWidget {
|
class RecipesScreen extends ConsumerWidget {
|
||||||
const RecipesScreen({super.key});
|
const RecipesScreen({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ConsumerState<RecipesScreen> createState() => _RecipesScreenState();
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
}
|
|
||||||
|
|
||||||
class _RecipesScreenState extends ConsumerState<RecipesScreen> {
|
|
||||||
int _selectedColumns = 2;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
_loadSelectedColumns();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _loadSelectedColumns() async {
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
setState(() {
|
|
||||||
_selectedColumns = prefs.getInt('selectedColumns') ?? 2;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _saveSelectedColumns(int columns) async {
|
|
||||||
final prefs = await SharedPreferences.getInstance();
|
|
||||||
await prefs.setInt('selectedColumns', columns);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final recipesAsync = ref.watch(recipesProvider);
|
final recipesAsync = ref.watch(recipesProvider);
|
||||||
|
final columns = ref.watch(recipesGridProvider).maybeWhen(
|
||||||
|
data: (v) => v,
|
||||||
|
orElse: () => 2,
|
||||||
|
);
|
||||||
|
|
||||||
return Scaffold(
|
return Stack(
|
||||||
appBar: AppBar(
|
children: [
|
||||||
title: const Text('Recept'),
|
recipesAsync.when(
|
||||||
actions: [
|
loading: () => const LoadingStateView(label: 'Laddar recept...'),
|
||||||
PopupMenuButton<int>(
|
error: (error, _) => ErrorStateView(
|
||||||
icon: const Icon(Icons.grid_view),
|
message: mapErrorToUserMessage(error, context),
|
||||||
tooltip: 'Välj antal kolumner',
|
onRetry: () => ref.invalidate(recipesProvider),
|
||||||
onSelected: (int columns) {
|
|
||||||
setState(() {
|
|
||||||
_selectedColumns = columns;
|
|
||||||
});
|
|
||||||
_saveSelectedColumns(columns);
|
|
||||||
},
|
|
||||||
itemBuilder: (BuildContext context) => <PopupMenuEntry<int>>[
|
|
||||||
const PopupMenuItem<int>(
|
|
||||||
value: 2,
|
|
||||||
child: Text('2 kolumner'),
|
|
||||||
),
|
|
||||||
const PopupMenuItem<int>(
|
|
||||||
value: 4,
|
|
||||||
child: Text('4 kolumner'),
|
|
||||||
),
|
|
||||||
const PopupMenuItem<int>(
|
|
||||||
value: 6,
|
|
||||||
child: Text('6 kolumner'),
|
|
||||||
),
|
|
||||||
const PopupMenuItem<int>(
|
|
||||||
value: 8,
|
|
||||||
child: Text('8 kolumner'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
],
|
data: (recipes) {
|
||||||
),
|
if (recipes.isEmpty) {
|
||||||
body: recipesAsync.when(
|
return const EmptyStateView(
|
||||||
loading: () => const LoadingStateView(label: 'Laddar recept...'),
|
title: 'Inga recept hittades',
|
||||||
error: (error, _) => ErrorStateView(
|
description: 'Lägg till ett recept för att komma igång.',
|
||||||
message: mapErrorToUserMessage(error, context),
|
);
|
||||||
onRetry: () => ref.invalidate(recipesProvider),
|
}
|
||||||
),
|
|
||||||
data: (recipes) {
|
|
||||||
if (recipes.isEmpty) {
|
|
||||||
return const EmptyStateView(
|
|
||||||
title: 'Inga recept hittades',
|
|
||||||
description: 'Lägg till ett recept för att komma igång.',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return GridView.count(
|
return GridView.builder(
|
||||||
crossAxisCount: _selectedColumns,
|
padding: const EdgeInsets.only(bottom: 88),
|
||||||
children: List.generate(
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
recipes.length,
|
crossAxisCount: columns,
|
||||||
(index) {
|
crossAxisSpacing: 4,
|
||||||
|
mainAxisSpacing: 4,
|
||||||
|
),
|
||||||
|
itemCount: recipes.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
final recipe = recipes[index];
|
final recipe = recipes[index];
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () => context.push('/recipes/${recipe.id}'),
|
onTap: () => context.push('/recipes/${recipe.id}'),
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: const EdgeInsets.all(4.0),
|
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(8.0),
|
borderRadius: BorderRadius.circular(8.0),
|
||||||
|
color: Colors.grey[200],
|
||||||
image: recipe.imageUrl != null
|
image: recipe.imageUrl != null
|
||||||
? DecorationImage(
|
? DecorationImage(
|
||||||
image: NetworkImage(recipe.imageUrl!),
|
image: NetworkImage(recipe.imageUrl!),
|
||||||
@@ -107,20 +58,24 @@ class _RecipesScreenState extends ConsumerState<RecipesScreen> {
|
|||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
child: recipe.imageUrl == null
|
child: recipe.imageUrl == null
|
||||||
? const Center(child: Icon(Icons.restaurant))
|
? const Center(child: Icon(Icons.restaurant, size: 32))
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
);
|
||||||
);
|
},
|
||||||
},
|
),
|
||||||
),
|
Positioned(
|
||||||
floatingActionButton: FloatingActionButton(
|
right: 16,
|
||||||
tooltip: 'Nytt recept',
|
bottom: 16,
|
||||||
onPressed: () => context.push('/recipes/create'),
|
child: FloatingActionButton(
|
||||||
child: const Icon(Icons.add),
|
tooltip: 'Nytt recept',
|
||||||
),
|
onPressed: () => context.push('/recipes/create'),
|
||||||
|
child: const Icon(Icons.add),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,12 @@
|
|||||||
|
# Senaste ändringar (2026-04-24)
|
||||||
|
|
||||||
|
**Arkitektur- och UX-förbättringar:**
|
||||||
|
- Grid-vy för recept: Kolumnval (2/4/6/8) via ikon i AppShell, med Riverpod-provider och SharedPreferences.
|
||||||
|
- RecipesScreen är nu body-only, ingen egen Scaffold/AppBar.
|
||||||
|
- AppShell visar grid-ikon endast på /recipes.
|
||||||
|
- Buggfix: Produktväljaren i pantry/inventarie (ProductPickerField) — bottenark implementeras.
|
||||||
|
- Kodkvalitet: Inga absoluta Windows-sökvägar.
|
||||||
|
- Dokumentation och next_steps uppdaterade.
|
||||||
# Next Steps: Flutter-migrering
|
# Next Steps: Flutter-migrering
|
||||||
|
|
||||||
Relaterade dokument:
|
Relaterade dokument:
|
||||||
|
|||||||
@@ -1,3 +1,12 @@
|
|||||||
|
# Senaste ändringar (2026-04-24)
|
||||||
|
|
||||||
|
**Arkitektur- och UX-förbättringar:**
|
||||||
|
- Grid-vy för recept: Kolumnval (2/4/6/8) via ikon i AppShell, med Riverpod-provider och SharedPreferences.
|
||||||
|
- RecipesScreen är nu body-only, ingen egen Scaffold/AppBar.
|
||||||
|
- AppShell visar grid-ikon endast på /recipes.
|
||||||
|
- Buggfix: Produktväljaren i pantry/inventarie (ProductPickerField) — bottenark implementeras.
|
||||||
|
- Kodkvalitet: Inga absoluta Windows-sökvägar.
|
||||||
|
- Dokumentation och next_steps uppdaterade.
|
||||||
# Teknisk Beskrivning - Flutter Frontend
|
# Teknisk Beskrivning - Flutter Frontend
|
||||||
Viktigt att komma ihåg vid implementering av nya funktioner och kodning är att inte använda windows sökvägar. Att inte använda c:/dev/recpie-app.... Detta eftersom bygg- och testmiljön är på en remote ubuntu-server. Utveckling sker lokalt och test samt drift
|
Viktigt att komma ihåg vid implementering av nya funktioner och kodning är att inte använda windows sökvägar. Att inte använda c:/dev/recpie-app.... Detta eftersom bygg- och testmiljön är på en remote ubuntu-server. Utveckling sker lokalt och test samt drift
|
||||||
sker på remote server. Säkerställ att inga absoluta Windows-sökvägar används i koden, för att stödja bygg och drift på Linux/Ubuntu
|
sker på remote server. Säkerställ att inga absoluta Windows-sökvägar används i koden, för att stödja bygg och drift på Linux/Ubuntu
|
||||||
|
|||||||
Reference in New Issue
Block a user