recipes can be added to db from createpage
This commit is contained in:
@@ -30,4 +30,6 @@ class DbHelper {
|
||||
static bool deleteRecipe(Recipe recipe) {
|
||||
return _isar.write((isar) => isar.recipes.delete(recipe.id));
|
||||
}
|
||||
|
||||
static Stream<void> get recipesChangedStream => _isar.recipes.watchLazy();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,11 @@ import 'package:rezepte/services/providers/db/dbhelper.dart';
|
||||
import '../../models/recipe.dart';
|
||||
|
||||
class RecipeListProvider extends ChangeNotifier {
|
||||
RecipeListProvider() {
|
||||
DbHelper.recipesChangedStream.listen((event) {
|
||||
notifyListeners();
|
||||
});
|
||||
}
|
||||
// final List<Recipe> _recipes = [];
|
||||
|
||||
// set recipes(List<Recipe> recipes) {
|
||||
@@ -20,8 +25,7 @@ class RecipeListProvider extends ChangeNotifier {
|
||||
// if (!silent) notifyListeners();
|
||||
// }
|
||||
|
||||
void addRecipe(Recipe recipe, {silent = false}) {
|
||||
void addRecipe(Recipe recipe) {
|
||||
DbHelper.putRecipe(recipe);
|
||||
if (!silent) notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ import '../../models/recipe.dart';
|
||||
class RecipeProvider extends ChangeNotifier {
|
||||
Recipe? _recipe;
|
||||
|
||||
Recipe get recipe => _recipe ??= Recipe(id: 0, title: '');
|
||||
Recipe? get recipe => _recipe;
|
||||
|
||||
set recipe(Recipe recipe) {
|
||||
set recipe(Recipe? recipe) {
|
||||
_recipe = recipe;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user