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: const CustomDrawer(initialIndex: 1), body: SizedBox( 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: const 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 const NoContentError(); return ListView.builder( itemCount: filteredRecipeList.length, itemBuilder: (context, index) => RecipeCard( recipe: filteredRecipeList[index], redrawCallback: redrawFavoritesView, showToastCallback: showToastCallback, ), ); } }