added confirm dialog when saving a recipe

This commit is contained in:
broodjeaap89 2021-09-06 20:45:56 +02:00
parent ce9ddf3722
commit a70f561eaa
2 changed files with 33 additions and 7 deletions

View file

@ -163,12 +163,9 @@ class AddRecipePageState extends State<AddRecipePage> {
width: double.infinity,
child: TextButton(
onPressed: () async {
if (pizzaRecipe.isInBox){
pizzaRecipe.save();
} else {
final pizzaRecipesBox = await Hive.openBox<PizzaRecipe>("PizzaRecipes");
pizzaRecipesBox.add(pizzaRecipe);
}
showDialog(context: context, builder: (BuildContext context) {
return buildConfirmSaveDialog();
});
},
child: const Text("Save", style: TextStyle(color: Colors.white)),
)
@ -177,6 +174,36 @@ class AddRecipePageState extends State<AddRecipePage> {
),
);
}
AlertDialog buildConfirmSaveDialog(){
return AlertDialog(
title: const Text("Save?"),
content: const Text("Are you sure you want to save the Pizza Recipe?"),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text("No"),
),
TextButton(
onPressed: () async {
if (pizzaRecipe.isInBox){
pizzaRecipe.save();
} else {
final pizzaRecipesBox = await Hive.openBox<PizzaRecipe>("PizzaRecipes");
pizzaRecipesBox.add(pizzaRecipe);
}
if (!mounted){
return;
}
Navigator.pop(context);
},
child: const Text("Yes"),
),
]
);
}
Widget buildIngredientRow(Ingredient ingredient){
return Row(

View file

@ -1,7 +1,6 @@
# TODO
## Feature
- confirm save recipe, maybe jump back to the recipes page with toast popup
- add way to remove recipes
- add search to recipes page
- add directory structure to recipes?