changed provider to work with database
This commit is contained in:
@@ -2,27 +2,26 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'package:rezepte/services/providers/db/dbhelper.dart';
|
import 'package:rezepte/services/providers/db/dbhelper.dart';
|
||||||
|
|
||||||
import '../../models/recipe.dart';
|
import '../../models/recipe.dart';
|
||||||
import 'package:rezepte/example_data.dart' as e;
|
|
||||||
|
|
||||||
class RecipeListProvider extends ChangeNotifier {
|
class RecipeListProvider extends ChangeNotifier {
|
||||||
final List<Recipe> _recipes = kDebugMode ? e.exampleRecipes : [];
|
// final List<Recipe> _recipes = [];
|
||||||
|
|
||||||
set recipes(List<Recipe> recipes) {
|
// set recipes(List<Recipe> recipes) {
|
||||||
_recipes.clear();
|
// _recipes.clear();
|
||||||
_recipes.addAll(recipes);
|
// _recipes.addAll(recipes);
|
||||||
notifyListeners();
|
// notifyListeners();
|
||||||
}
|
// }
|
||||||
|
|
||||||
List<Recipe> get recipes => DbHelper.fetchRecipes(); // _recipes;
|
List<Recipe> get recipes => DbHelper.fetchRecipes(); // _recipes;
|
||||||
|
|
||||||
void clearRecipes({silent = false}) {
|
// void clearRecipes({silent = false}) {
|
||||||
_recipes.clear();
|
// _recipes.clear();
|
||||||
|
|
||||||
if (!silent) notifyListeners();
|
// if (!silent) notifyListeners();
|
||||||
}
|
// }
|
||||||
|
|
||||||
void addRecipe(Recipe recipe, {silent = false}) {
|
void addRecipe(Recipe recipe, {silent = false}) {
|
||||||
_recipes.add(recipe);
|
DbHelper.putRecipe(recipe);
|
||||||
if (!silent) notifyListeners();
|
if (!silent) notifyListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user