changes to recipe class and providers

This commit is contained in:
SomnusVeritas
2023-11-05 20:54:57 +01:00
parent 1580ec723a
commit b17078cdef
6 changed files with 91 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import '../../models/recipe.dart';
class RecipeListProvider extends ChangeNotifier {
final List<Recipe> _recipes = [];
set recipes(List<Recipe> recipes) {
_recipes.clear();
_recipes.addAll(recipes);
notifyListeners();
}
List<Recipe> get recipes => _recipes;
void clearRecipes({silent = false}) {
_recipes.clear();
if (!silent) notifyListeners();
}
void addRecipe(Recipe recipe, {silent = false}) {
_recipes.add(recipe);
if (!silent) notifyListeners();
}
}

View File

@@ -62,21 +62,25 @@ class RecipeProvider extends ChangeNotifier implements Recipe {
@override
List<IngredientListEntry> get ingredients => _ingredients;
@override
void addIngredient(IngredientListEntry ingredient) {
_ingredients.add(ingredient);
notifyListeners();
}
@override
void clearIngredients({silent = false}) {
ingredients.clear();
if (!silent) notifyListeners();
}
@override
void removeIngredientAt(int index, {silent = false}) {
ingredients.removeAt(index);
if (!silent) notifyListeners();
}
@override
void removeIngredient(IngredientListEntry ingredient, {silent = false}) {
ingredients.removeWhere((element) => element == ingredient);
if (!silent) notifyListeners();
@@ -85,11 +89,13 @@ class RecipeProvider extends ChangeNotifier implements Recipe {
@override
List<CookingStep> get steps => _steps;
@override
void addStep(CookingStep step, {silent = false}) {
steps.add(step);
if (!silent) notifyListeners();
}
@override
void removeStepAt(int index, {silent = false}) {
steps.removeAt(index);
if (!silent) notifyListeners();