diff options
author | davidpkj <davidpenkow1@gmail.com> | 2022-07-17 19:25:26 +0200 |
---|---|---|
committer | davidpkj <davidpenkow1@gmail.com> | 2022-07-17 19:25:26 +0200 |
commit | d282f4bb380ce9c445d6bd3a4c9f001bb6b5f501 (patch) | |
tree | 023428b7fa249b66a34d0d83c2f0df0ea572ba75 /lib/views/favorites_view.dart |
Initial Commit
Diffstat (limited to 'lib/views/favorites_view.dart')
-rw-r--r-- | lib/views/favorites_view.dart | 82 |
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, + ), + ); + } +} |