Skip to content

Commit

Permalink
Added search field
Browse files Browse the repository at this point in the history
  • Loading branch information
judemont committed Apr 8, 2024
1 parent 401ca42 commit bc03309
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 110 deletions.
76 changes: 0 additions & 76 deletions .github/workflows/flutter-build-bundle.yml

This file was deleted.

5 changes: 3 additions & 2 deletions lib/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ class DatabaseService {
return id;
}

static Future<List<Recipe>> getRecipes() async {
static Future<List<Recipe>> getRecipes({String searchQuery = ""}) async {
final db = await DatabaseService.initializeDb();

final List<Map<String, Object?>> queryResult = await db.query('Recipes');
final List<Map<String, Object?>> queryResult =
await db.query('Recipes', where: "title LIKE '%$searchQuery%'");
return queryResult.map((e) => Recipe.fromMap(e)).toList();
}

Expand Down
83 changes: 51 additions & 32 deletions lib/widgets/homePage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class HomePage extends StatefulWidget {
class _HomePageState extends State<HomePage> {
List<Recipe> recipes = [];
List<int> selectedRecipes = [];
bool displaySearchField = false;

@override
void initState() {
Expand All @@ -26,41 +27,59 @@ class _HomePageState extends State<HomePage> {
Widget build(BuildContext context) {
print(selectedRecipes);
return Scaffold(
appBar: AppBar(
title: const Text("Reciper"),
centerTitle: true,
actions: [
if (selectedRecipes.isNotEmpty)
IconButton(
onPressed: () {
removeSelectedRecipes(selectedRecipes).then((value) {
loadRecipes();
});
},
icon: const Icon(Icons.delete)),
],
),
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ExtractRecipeButton(reloadRecipes: loadRecipes),
const SizedBox(height: 10),
NewRecipeButton(reloadRecipes: loadRecipes),
],
),
body: SingleChildScrollView(
child: RecipeListView(
reloadRecipes: loadRecipes,
recipes: recipes,
onRecipesSelectionUpdate: onRecipesSelectionUpdate,
selectedRecipesID: selectedRecipes,
appBar: AppBar(
title: const Text("Reciper"),
centerTitle: true,
leading: IconButton(
onPressed: () {
setState(() {
displaySearchField = !displaySearchField;
});
},
icon: const Icon(Icons.search)),
actions: [
if (selectedRecipes.isNotEmpty)
IconButton(
onPressed: () {
removeSelectedRecipes(selectedRecipes).then((value) {
loadRecipes();
});
},
icon: const Icon(Icons.delete)),
],
),
),
);
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ExtractRecipeButton(reloadRecipes: loadRecipes),
const SizedBox(height: 10),
NewRecipeButton(reloadRecipes: loadRecipes),
],
),
body: Column(
children: [
Visibility(
visible: displaySearchField,
child: TextField(
onChanged: (value) {
loadRecipes(searchQuery: value);
},
)),
SingleChildScrollView(
child: RecipeListView(
reloadRecipes: loadRecipes,
recipes: recipes,
onRecipesSelectionUpdate: onRecipesSelectionUpdate,
selectedRecipesID: selectedRecipes,
),
),
],
));
}

Future<void> loadRecipes() async {
DatabaseService.getRecipes().then((List<Recipe> result) {
Future<void> loadRecipes({searchQuery = ""}) async {
DatabaseService.getRecipes(searchQuery: searchQuery)
.then((List<Recipe> result) {
setState(() {
print("recipes LOAD:");
print(recipes);
Expand Down

0 comments on commit bc03309

Please sign in to comment.