diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 1239a6d..7af515c 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -25,7 +25,6 @@ class _HomePageState extends State { loadRecipes(); loadTags().then((value) { selectedTagsId.clear(); - print(tags.toString() + "NNNN"); selectedTagsId.addAll(tags.map((e) => e.id!).toList()); }); @@ -81,6 +80,9 @@ class _HomePageState extends State { body: SingleChildScrollView( child: Column( children: [ + const SizedBox( + height: 20, + ), Visibility( visible: displaySearchField, child: SizedBox( @@ -94,6 +96,22 @@ class _HomePageState extends State { loadRecipes(searchQuery: value); }, ))), + const SizedBox( + height: 20, + ), + Visibility( + visible: selectedTagsId.length != tags.length, + child: ElevatedButton( + child: const Text("Remove filters"), + onPressed: () { + setState(() { + selectedTagsId.clear(); + selectedTagsId.addAll(tags.map((e) => e.id!).toList()); + }); + loadRecipes(); + }, + ), + ), RecipeListView( reloadRecipes: loadRecipes, recipes: recipes, @@ -105,7 +123,6 @@ class _HomePageState extends State { } Future loadRecipes({searchQuery = ""}) async { - print(selectedTagsId); if (selectedTagsId.length == tags.length) { DatabaseService.getRecipes(searchQuery: searchQuery) .then((List result) { @@ -114,7 +131,6 @@ class _HomePageState extends State { }); }); } else { - print("FILTERRRR"); setState(() { recipes = []; }); @@ -123,7 +139,6 @@ class _HomePageState extends State { DatabaseService.getRecipesFromTag(tagId, searchQuery: searchQuery) .then((values) { for (var recipe in values) { - print(recipe.title ?? "" + "UUU"); if (!recipes.contains(recipe)) { setState(() { recipes.add(recipe); @@ -144,10 +159,10 @@ class _HomePageState extends State { } Future onTagsSelectionUpdate(List values) async { + print(values); setState(() { selectedTagsId = values; }); - print(selectedTagsId.toString() + " tags selected"); loadRecipes(); } diff --git a/lib/screens/recipe_editor.dart b/lib/screens/recipe_editor.dart index 387047e..6a6bf95 100644 --- a/lib/screens/recipe_editor.dart +++ b/lib/screens/recipe_editor.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; import 'package:reciper/models/tag.dart'; import 'package:reciper/screens/pages_layout.dart'; import 'package:reciper/utilities/database.dart'; @@ -124,7 +123,7 @@ class _RecipeEditorPageState extends State { ), ), SizedBox(height: fieldsMargin), - Container( + SizedBox( height: 50, child: Row( children: [ @@ -212,7 +211,7 @@ class _RecipeEditorPageState extends State { Future onTagsSelectionUpdate(List values) async { setState(() { selectedTagsId = values; - print(selectedTagsId.toString() + "çççççççççççççççç"); + print("$selectedTagsIdçççççççççççççççç"); }); } } diff --git a/lib/utilities/database.dart b/lib/utilities/database.dart index c515cf7..d463ccb 100644 --- a/lib/utilities/database.dart +++ b/lib/utilities/database.dart @@ -153,7 +153,7 @@ class DatabaseService { List> tag = await db.query('Tags', where: "id = ${tagLink['tagId']}"); - recipeTags.add(Tag.fromMap(tag[0])); + tag.isNotEmpty ? recipeTags.add(Tag.fromMap(tag[0])) : null; } return recipeTags; diff --git a/lib/widgets/recipeTagSelector.dart b/lib/widgets/recipeTagSelector.dart index 1d8abb7..80feef8 100644 --- a/lib/widgets/recipeTagSelector.dart +++ b/lib/widgets/recipeTagSelector.dart @@ -1,4 +1,3 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:reciper/models/tag.dart'; import 'package:reciper/widgets/newTagDialog.dart'; diff --git a/lib/widgets/tagsSelector.dart b/lib/widgets/tagsSelector.dart index 4f9cb67..d2e68cb 100644 --- a/lib/widgets/tagsSelector.dart +++ b/lib/widgets/tagsSelector.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:reciper/models/tag.dart'; -import 'package:reciper/utilities/database.dart'; import 'package:reciper/widgets/newTagDialog.dart'; import 'package:reciper/widgets/tagActionsDialog.dart'; @@ -12,12 +11,11 @@ class TagsSelector extends StatefulWidget { final Function onTagsUpdate; const TagsSelector( - {Key? key, + {super.key, required this.tags, required this.onTagsUpdate, required this.selectedTagsId, - required this.onTagsSelectionUpdate}) - : super(key: key); + required this.onTagsSelectionUpdate}); @override State createState() => _TagsSelectorState(); @@ -89,7 +87,9 @@ class _TagsSelectorState extends State { onChanged: (value) { setState(() { if (value ?? false) { - widget.selectedTagsId.add(widget.tags[index].id!); + !widget.selectedTagsId.contains(widget.tags[index].id!) + ? widget.selectedTagsId.add(widget.tags[index].id!) + : null; } else { widget.selectedTagsId.remove(widget.tags[index].id); }