import 'package:flutter/material.dart'; import '../../models/ingredient_list_entry.dart'; import '../../models/recipe.dart'; import '../../src/enums.dart'; class RecipeProvider extends ChangeNotifier { Recipe _recipe = Recipe(datePublished: DateTime.now()); Recipe get recipe => _recipe; void updateTitle(String title, {bool silent = false}) { _recipe = _recipe.copyWith(title: title); if (!silent) { notifyListeners(); } } void updateDescription(String description, {bool silent = false}) { _recipe = _recipe.copyWith(description: description); if (!silent) { notifyListeners(); } } void updateDifficulty(Difficulty difficulty, {bool silent = false}) { _recipe = _recipe.copyWith(difficulty: difficulty); if (!silent) { notifyListeners(); } } void updateIngredients(List ingredients, {bool silent = false}) { _recipe = _recipe.copyWith(ingredients: ingredients); if (!silent) { notifyListeners(); } } void updateSteps(List steps, {bool silent = false}) { _recipe = _recipe.copyWith(steps: steps); if (!silent) { notifyListeners(); } } void updateDatePublished(DateTime datePublished, {bool silent = false}) { _recipe = _recipe.copyWith(datePublished: datePublished); if (!silent) { notifyListeners(); } } void updatePrepTime(Duration prepTime, {bool silent = false}) { _recipe = _recipe.copyWith(prepTime: prepTime); if (!silent) { notifyListeners(); } } void updateCookTime(Duration cookTime, {bool silent = false}) { _recipe = _recipe.copyWith(cookTime: cookTime); if (!silent) { notifyListeners(); } } void updateKeywords(List keywords, {bool silent = false}) { _recipe = _recipe.copyWith(keywords: keywords); if (!silent) { notifyListeners(); } } void updateMealCategory(MealCategory mealCategory, {bool silent = false}) { _recipe = _recipe.copyWith(mealCategory: mealCategory); if (!silent) { notifyListeners(); } } void updateCuisine(Cuisine cuisine, {bool silent = false}) { _recipe = _recipe.copyWith(cuisine: cuisine); if (!silent) { notifyListeners(); } } // Helper methods for list operations void addIngredient(IngredientListEntry ingredient, {bool silent = false}) { _recipe = _recipe.copyWith( ingredients: [..._recipe.ingredients, ingredient], ); if (!silent) { notifyListeners(); } } void removeIngredient(IngredientListEntry ingredient, {bool silent = false}) { _recipe = _recipe.copyWith( ingredients: _recipe.ingredients.where((i) => i != ingredient).toList(), ); if (!silent) { notifyListeners(); } } void addStep(String step, {bool silent = false}) { _recipe = _recipe.copyWith( steps: [..._recipe.steps, step], ); if (!silent) { notifyListeners(); } } void removeStep(String step, {bool silent = false}) { _recipe = _recipe.copyWith( steps: _recipe.steps.where((s) => s != step).toList(), ); if (!silent) { notifyListeners(); } } void addKeyword(String keyword, {bool silent = false}) { _recipe = _recipe.copyWith( keywords: [..._recipe.keywords, keyword], ); if (!silent) { notifyListeners(); } } void removeKeyword(String keyword, {bool silent = false}) { _recipe = _recipe.copyWith( keywords: _recipe.keywords.where((k) => k != keyword).toList(), ); if (!silent) { notifyListeners(); } } void disposeRecipe() { _recipe = Recipe(datePublished: DateTime.now()); } }