From d282f4bb380ce9c445d6bd3a4c9f001bb6b5f501 Mon Sep 17 00:00:00 2001 From: davidpkj Date: Sun, 17 Jul 2022 19:25:26 +0200 Subject: Initial Commit --- lib/views/favorites_view.dart | 82 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 lib/views/favorites_view.dart (limited to 'lib/views/favorites_view.dart') 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 { + 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 _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, + ), + ); + } +} -- cgit v1.2.3