e495a4b38e
- Introduced MealPlanApiPaths for handling meal plan related API endpoints. - Added MealPlanScreen for displaying and managing meal plans. - Implemented MealPlanRepository for fetching and updating meal plan data. - Created data models: MealPlanEntry, MealPlanRecipe, InventoryCompareItem, ShoppingItem, and MealPlanDashboard. - Integrated meal plan functionality into the app router and UI. - Updated localization files for meal plan related strings in English and Swedish. - Added state management for meal plan using Riverpod.
41 lines
1.5 KiB
Dart
41 lines
1.5 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../../core/api/api_providers.dart';
|
|
import '../../../core/api/guarded_api_call.dart';
|
|
import '../../auth/data/auth_providers.dart';
|
|
import '../domain/meal_plan_dashboard.dart';
|
|
import '../domain/meal_plan_week.dart';
|
|
import 'meal_plan_repository.dart';
|
|
|
|
final mealPlanRepositoryProvider = Provider<MealPlanRepository>((ref) {
|
|
return MealPlanRepository(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final mealPlanWeekOffsetProvider = StateProvider<int>((ref) => 0);
|
|
|
|
final mealPlanWeekProvider = Provider<MealPlanWeek>((ref) {
|
|
final offset = ref.watch(mealPlanWeekOffsetProvider);
|
|
return MealPlanWeek.fromOffset(offset);
|
|
});
|
|
|
|
final mealPlanDashboardProvider = FutureProvider<MealPlanDashboard>((ref) async {
|
|
final week = ref.watch(mealPlanWeekProvider);
|
|
final token = await ref.watch(authStateProvider.future);
|
|
|
|
return guardedApiCall(ref, () async {
|
|
final repository = ref.read(mealPlanRepositoryProvider);
|
|
final entries = await repository.fetchEntries(week.fromIso, week.toIso, token: token);
|
|
final shoppingItems = await repository.fetchShoppingList(week.fromIso, week.toIso, token: token);
|
|
final inventoryCompareItems = await repository.fetchInventoryCompare(
|
|
week.fromIso,
|
|
week.toIso,
|
|
token: token,
|
|
);
|
|
|
|
return MealPlanDashboard(
|
|
entries: entries,
|
|
shoppingItems: shoppingItems,
|
|
inventoryCompareItems: inventoryCompareItems,
|
|
);
|
|
});
|
|
}); |