added long press on pizza recipes page to edit existing recipes

This commit is contained in:
broodjeaap89 2021-09-05 17:48:21 +02:00
parent de9e5f8ba6
commit 2048c88d0c
4 changed files with 15 additions and 8 deletions

View file

@ -171,7 +171,7 @@ class RouteGenerator {
return MaterialPageRoute(builder: (context) => RecipesPage()); return MaterialPageRoute(builder: (context) => RecipesPage());
} }
case "/recipes/add": { case "/recipes/add": {
return MaterialPageRoute(builder: (context) => AddRecipePage()); return MaterialPageRoute(builder: (context) => AddRecipePage(pizzaRecipe: settings.arguments as PizzaRecipe?));
} }
case "/recipes/add/edit_step": { case "/recipes/add/edit_step": {
final recipeStep = settings.arguments as RecipeStep?; final recipeStep = settings.arguments as RecipeStep?;

View file

@ -9,9 +9,11 @@ import 'package:pizzaplanner/pages/scaffold.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
class AddRecipePage extends StatefulWidget { class AddRecipePage extends StatefulWidget {
final PizzaRecipe? pizzaRecipe; late final PizzaRecipe? _pizzaRecipe;
const AddRecipePage({this.pizzaRecipe}); AddRecipePage({PizzaRecipe? pizzaRecipe}){
_pizzaRecipe = pizzaRecipe;
}
@override @override
AddRecipePageState createState() => AddRecipePageState(); AddRecipePageState createState() => AddRecipePageState();
@ -26,7 +28,7 @@ class AddRecipePageState extends State<AddRecipePage> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
if (widget.pizzaRecipe == null){ if (widget._pizzaRecipe == null){
pizzaRecipe = PizzaRecipe( pizzaRecipe = PizzaRecipe(
"", "",
"", "",
@ -38,7 +40,7 @@ class AddRecipePageState extends State<AddRecipePage> {
], ],
); );
} else { } else {
pizzaRecipe = widget.pizzaRecipe!; pizzaRecipe = widget._pizzaRecipe!;
} }
} }
@ -56,7 +58,7 @@ class AddRecipePageState extends State<AddRecipePage> {
hintText: "Recipe Name", hintText: "Recipe Name",
errorText: nameValidation ? """Name can't be empty""" : null errorText: nameValidation ? """Name can't be empty""" : null
), ),
initialValue: widget.pizzaRecipe?.name, initialValue: widget._pizzaRecipe?.name,
onChanged: (String newName) { onChanged: (String newName) {
setState(() { setState(() {
pizzaRecipe.name = newName; pizzaRecipe.name = newName;
@ -69,7 +71,7 @@ class AddRecipePageState extends State<AddRecipePage> {
hintText: "Recipe Description", hintText: "Recipe Description",
errorText: descriptionValidation ? """Description can't be empty""" : null errorText: descriptionValidation ? """Description can't be empty""" : null
), ),
initialValue: widget.pizzaRecipe?.description, initialValue: widget._pizzaRecipe?.description,
maxLines: 8, maxLines: 8,
onChanged: (String newDescription) { onChanged: (String newDescription) {
setState(() { setState(() {

View file

@ -27,6 +27,8 @@ class RecipesPage extends StatelessWidget {
) )
), ),
const Divider(), const Divider(),
const Center(child: Text("Long press to edit")),
const Divider(),
Expanded( Expanded(
flex: 50, flex: 50,
child: ValueListenableBuilder( child: ValueListenableBuilder(
@ -43,6 +45,9 @@ class RecipesPage extends StatelessWidget {
onTap: () { onTap: () {
Navigator.pushNamed(context, "/recipe/view", arguments: pizzaRecipe); Navigator.pushNamed(context, "/recipe/view", arguments: pizzaRecipe);
}, },
onLongPress: () {
Navigator.pushNamed(context, "/recipes/add", arguments: pizzaRecipe);
},
child: PizzaRecipeWidget(pizzaRecipe), child: PizzaRecipeWidget(pizzaRecipe),
); );
}, },

View file

@ -1,7 +1,7 @@
# TODO # TODO
## Feature ## Feature
- longpress recipe to edit it on recipes page? - add way to remove recipes
- add search to recipes page - add search to recipes page
- add directory structure to recipes? - add directory structure to recipes?
- share to/export of yaml of recipes - share to/export of yaml of recipes