changes to recipe class and providers
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import 'package:rezepte/models/difficulty.dart';
|
||||
import 'package:rezepte/models/unit.dart';
|
||||
|
||||
import 'models/ingredient.dart';
|
||||
import 'constants.dart' as constants;
|
||||
import 'models/recipe.dart';
|
||||
|
||||
final List<Unit> _weightAndCount = constants.units
|
||||
.where((element) =>
|
||||
@@ -25,3 +27,14 @@ final List<Ingredient> exampleIngredients = [
|
||||
Ingredient(title: 'Milch', possibleUnits: _fluid),
|
||||
Ingredient(title: 'Limettenblätter', possibleUnits: _count),
|
||||
];
|
||||
|
||||
final List<Recipe> exampleRecipes = [
|
||||
Recipe(
|
||||
title: 'Wraps',
|
||||
description: 'Nur ein paar Wraps',
|
||||
difficulty: Difficulty.hard),
|
||||
Recipe(
|
||||
title: 'Burritos',
|
||||
description: 'Nur ein paar Burritos',
|
||||
difficulty: Difficulty.easy),
|
||||
];
|
||||
|
||||
@@ -2,12 +2,16 @@ import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:rezepte/pages/create_recipe_page.dart';
|
||||
import 'package:rezepte/pages/dashboard_page.dart';
|
||||
import 'package:rezepte/services/providers/recipe_list_provider.dart';
|
||||
import 'package:rezepte/services/providers/recipe_provider.dart';
|
||||
|
||||
import 'theme.dart';
|
||||
|
||||
void main() {
|
||||
runApp(MultiProvider(providers: [
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => RecipeListProvider(),
|
||||
),
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => RecipeProvider(),
|
||||
),
|
||||
|
||||
@@ -6,12 +6,31 @@ class Recipe {
|
||||
final String title;
|
||||
final String description;
|
||||
final Difficulty? difficulty;
|
||||
final List<IngredientListEntry> ingredients = [];
|
||||
final List<CookingStep> steps = [];
|
||||
final List<IngredientListEntry> ingredients;
|
||||
final List<CookingStep> steps;
|
||||
|
||||
Recipe({
|
||||
required this.title,
|
||||
this.description = '',
|
||||
this.difficulty,
|
||||
this.ingredients = const [],
|
||||
this.steps = const [],
|
||||
});
|
||||
|
||||
void addIngredient(IngredientListEntry ingredient) =>
|
||||
ingredients.add(ingredient);
|
||||
|
||||
void clearIngredients() => ingredients.clear();
|
||||
|
||||
void removeIngredientAt(int index) {
|
||||
ingredients.removeAt(index);
|
||||
}
|
||||
|
||||
void removeIngredient(IngredientListEntry ingredient) {
|
||||
ingredients.removeWhere((element) => element == ingredient);
|
||||
}
|
||||
|
||||
void addStep(CookingStep step) => steps.add(step);
|
||||
|
||||
void removeStepAt(int index) => steps.removeAt(index);
|
||||
}
|
||||
|
||||
26
lib/services/providers/recipe_list_provider.dart
Normal file
26
lib/services/providers/recipe_list_provider.dart
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
21
lib/widgets/recipe_list.dart
Normal file
21
lib/widgets/recipe_list.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:rezepte/services/providers/recipe_list_provider.dart';
|
||||
|
||||
class RecipeList extends StatelessWidget {
|
||||
const RecipeList({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final recipes =
|
||||
Provider.of<RecipeListProvider>(context, listen: true).recipes;
|
||||
return ListView.builder(
|
||||
itemCount: recipes.length,
|
||||
itemBuilder: _recipeListBuilder,
|
||||
);
|
||||
}
|
||||
|
||||
Widget? _recipeListBuilder(BuildContext context, int index) {
|
||||
return Card();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user