From 3c3dfe706ac9911a1066aace8866375363eb1d6d Mon Sep 17 00:00:00 2001 From: broodjeaap89 Date: Thu, 9 Sep 2021 19:58:54 +0200 Subject: [PATCH] added search to recipes page --- lib/pages/recipes_page.dart | 55 +++++++++++++++++++++++++++---------- todo.md | 2 -- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/lib/pages/recipes_page.dart b/lib/pages/recipes_page.dart index 356a749..2fb0d15 100644 --- a/lib/pages/recipes_page.dart +++ b/lib/pages/recipes_page.dart @@ -5,26 +5,34 @@ import 'package:pizzaplanner/pages/nav_drawer.dart'; import 'package:pizzaplanner/pages/scaffold.dart'; import 'package:pizzaplanner/widgets/pizza_recipe_widget.dart'; -class RecipesPage extends StatelessWidget { + +class RecipesPage extends StatefulWidget { + @override + RecipesPageState createState() => RecipesPageState(); +} + +class RecipesPageState extends State { + String searchText = ""; + @override Widget build(BuildContext context){ return PizzaPlannerScaffold( title: const Text("Pizza Recipes"), body: Column( children: [ - const Expanded( + Expanded( flex: 5, - child: Text("Search here maybe") - ), - Container( - color: Colors.blue, - width: double.infinity, - child: TextButton( - onPressed: () async { - Navigator.pushNamed(context, "/recipes/edit"); + child: TextFormField( + decoration: const InputDecoration( + hintText: "Search Recipes", + ), + initialValue: searchText, + onChanged: (String newSearch) { + setState(() { + searchText = newSearch; + }); }, - child: const Text("New Recipe", style: TextStyle(color: Colors.white)), - ) + ), ), const Divider(), const Center(child: Text("Long press to edit")), @@ -38,7 +46,10 @@ class RecipesPage extends StatelessWidget { itemCount: pizzaRecipesBox.length, itemBuilder: (context, i) { final pizzaRecipe = pizzaRecipesBox.get(i); - if (pizzaRecipe == null || pizzaRecipe.deleted){ + if ( + pizzaRecipe == null || + pizzaRecipe.deleted || + (searchText.isNotEmpty && !pizzaRecipe.name.toLowerCase().contains(searchText))){ return const SizedBox(); } return InkWell( @@ -104,7 +115,10 @@ class RecipesPage extends StatelessWidget { }, separatorBuilder: (BuildContext context, int i) { final pizzaRecipe = pizzaRecipesBox.get(i); - if (pizzaRecipe == null || pizzaRecipe.deleted){ + if ( + pizzaRecipe == null || + pizzaRecipe.deleted || + (searchText.isNotEmpty && !pizzaRecipe.name.toLowerCase().contains(searchText))){ return const SizedBox(); } return const Divider(); @@ -112,7 +126,18 @@ class RecipesPage extends StatelessWidget { ); } ), - ) + ), + const Divider(), + Container( + color: Colors.blue, + width: double.infinity, + child: TextButton( + onPressed: () async { + Navigator.pushNamed(context, "/recipes/edit"); + }, + child: const Text("New Recipe", style: TextStyle(color: Colors.white)), + ) + ), ] ), ); diff --git a/todo.md b/todo.md index be5a521..1ca2b3c 100644 --- a/todo.md +++ b/todo.md @@ -1,8 +1,6 @@ # TODO ## Feature -- add search to recipes page -- add directory structure to recipes? - share to/export of yaml of recipes - add an import of recipes from raw url - maybe allow a 'dir' yaml, that just points to other raw pizza yaml urls