feat: add meal planning feature with API integration
- 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.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class MealPlanWeek {
|
||||
final DateTime start;
|
||||
final List<DateTime> days;
|
||||
|
||||
const MealPlanWeek({
|
||||
required this.start,
|
||||
required this.days,
|
||||
});
|
||||
|
||||
factory MealPlanWeek.fromOffset(int offset) {
|
||||
final now = DateTime.now();
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
final monday = today.subtract(Duration(days: today.weekday - 1)).add(
|
||||
Duration(days: offset * 7),
|
||||
);
|
||||
|
||||
return MealPlanWeek(
|
||||
start: monday,
|
||||
days: List.generate(
|
||||
7,
|
||||
(index) => DateTime(monday.year, monday.month, monday.day + index),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
DateTime get end => days.last;
|
||||
|
||||
String get fromIso => isoDate(start);
|
||||
String get toIso => isoDate(end);
|
||||
|
||||
String isoDate(DateTime date) => DateFormat('yyyy-MM-dd').format(date);
|
||||
}
|
||||
Reference in New Issue
Block a user