aboutsummaryrefslogtreecommitdiff
path: root/lib/views/favorites_view.dart
diff options
context:
space:
mode:
Diffstat (limited to 'lib/views/favorites_view.dart')
-rw-r--r--lib/views/favorites_view.dart82
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/views/favorites_view.dart b/lib/views/favorites_view.dart
new file mode 100644
index 0000000..bb0f7fb
--- /dev/null
+++ b/lib/views/favorites_view.dart
@@ -0,0 +1,82 @@
+import 'package:flutter/material.dart';
+
+import 'package:kulinar_app/models/recipe_class.dart';
+import 'package:kulinar_app/widgets/error_widgets.dart';
+import 'package:kulinar_app/widgets/toastbar_widget.dart';
+import 'package:kulinar_app/widgets/recipe_card_widget.dart';
+import 'package:kulinar_app/widgets/custom_drawer_widget.dart';
+import 'package:kulinar_app/models/data/recipe_data_class.dart';
+import 'package:kulinar_app/widgets/recipe_search_delegate.dart';
+
+import 'package:flutter_gen/gen_l10n/app_localizations.dart';
+
+class FavoritesView extends StatefulWidget {
+ const FavoritesView({Key? key}) : super(key: key);
+
+ @override
+ _FavoritesViewState createState() => _FavoritesViewState();
+}
+
+class _FavoritesViewState extends State<FavoritesView> {
+ BuildContext? _toastyContext;
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ appBar: _buildAppBar(context),
+ drawer: CustomDrawer(initalIndex: 1),
+ body: Container(
+ width: double.infinity,
+ child: Builder(
+ builder: (BuildContext context) {
+ _toastyContext = context;
+
+ return _buildListView();
+ },
+ ),
+ ),
+ );
+ }
+
+ void redrawFavoritesView() {
+ setState(() {});
+ }
+
+ void showToastCallback(String content, String actionLabel, Function actionCallback) {
+ ToastBar.showToastBar(_toastyContext!, content, actionLabel: actionLabel, actionCallback: actionCallback);
+ }
+
+ PreferredSizeWidget _buildAppBar(BuildContext context) {
+ return AppBar(
+ title: Text(AppLocalizations.of(context)!.category4),
+ actions: [
+ IconButton(
+ icon: Icon(Icons.search),
+ onPressed: () async {
+ await showSearch(
+ context: context,
+ delegate: FavoriteRecipeSearch(),
+ );
+
+ setState(() {});
+ },
+ ),
+ ],
+ );
+ }
+
+ Widget _buildListView() {
+ List<Recipe> _filteredRecipeList = RecipeData.recipeList.where((element) => element.favorite).toList();
+
+ if (_filteredRecipeList.isEmpty) return NoContentError();
+
+ return ListView.builder(
+ itemCount: _filteredRecipeList.length,
+ itemBuilder: (context, index) => RecipeCard(
+ recipe: _filteredRecipeList[index],
+ redrawCallback: redrawFavoritesView,
+ showToastCallback: showToastCallback,
+ ),
+ );
+ }
+}