recipes can be added to db from createpage

This commit is contained in:
SomnusVeritas
2023-11-13 17:57:38 +01:00
parent 384744729b
commit 64e983bc59
5 changed files with 25 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:rezepte/services/providers/db/dbhelper.dart';
import 'package:rezepte/widgets/ingredients_bottomsheet.dart';
import 'package:rezepte/widgets/will_pop_scope.dart';
import '../models/difficulty.dart';
@@ -34,10 +35,17 @@ class _CreateRecipeState extends State<CreateRecipe> {
@override
Widget build(BuildContext context) {
recipe = Provider.of<RecipeProvider>(context).recipe;
recipeProvider = Provider.of<RecipeProvider>(context, listen: false);
recipeProvider = Provider.of<RecipeProvider>(context, listen: true);
recipeListProvider =
Provider.of<RecipeListProvider>(context, listen: false);
if (recipeProvider.recipe == null) {
recipe = Recipe(id: DbHelper.nextRecipeId, title: '');
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
recipeProvider.recipe = recipe;
});
}
return CustomWillPopScope(
context,
ignore: recipe.isEmpty,

View File

@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:rezepte/services/providers/recipe_provider.dart';
import '../models/recipe.dart';
class RecipeDetail extends StatelessWidget {
const RecipeDetail({super.key});
static const routeName = '/recipeDetail';
@@ -10,6 +12,9 @@ class RecipeDetail extends StatelessWidget {
Widget build(BuildContext context) {
final recipe = Provider.of<RecipeProvider>(context, listen: false).recipe;
if (recipe == null) Navigator.of(context).pop();
recipe as Recipe;
return Scaffold(
appBar: AppBar(),
body: Center(