From c2f0c3a62f1750e438a14d9608465294dcc8f904 Mon Sep 17 00:00:00 2001 From: rubuy-74 Date: Fri, 8 Dec 2023 18:47:15 +0000 Subject: [PATCH] Fix implementation and reorganize statements --- .../widgets/restaurant_page_card.dart | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/uni/lib/view/restaurant/widgets/restaurant_page_card.dart b/uni/lib/view/restaurant/widgets/restaurant_page_card.dart index 7b919d8ec..7e323e1c8 100644 --- a/uni/lib/view/restaurant/widgets/restaurant_page_card.dart +++ b/uni/lib/view/restaurant/widgets/restaurant_page_card.dart @@ -47,17 +47,22 @@ class CardFavoriteButton extends StatelessWidget { builder: (context, restaurantProvider) { final isFavorite = restaurantProvider.favoriteRestaurants.contains(restaurant.name); - final favoriteCardTypes = - Provider.of(context).favoriteCards; return IconButton( icon: isFavorite ? Icon(MdiIcons.heart) : Icon(MdiIcons.heartOutline), - onPressed: () => { + onPressed: () { restaurantProvider.toggleFavoriteRestaurant( restaurant.name, - ), + ); + final favoriteCardTypes = + context.read().favoriteCards; if (!isFavorite && - !favoriteCardTypes.contains(FavoriteWidgetType.restaurant)) - showRestaurantCardHomeDialog(context, favoriteCardTypes), + !favoriteCardTypes.contains(FavoriteWidgetType.restaurant)) { + showRestaurantCardHomeDialog(context, favoriteCardTypes, + (newFavoriteCards) { + Provider.of(context, listen: false) + .setFavoriteCards(newFavoriteCards); + }); + } }, ); }, @@ -67,6 +72,7 @@ class CardFavoriteButton extends StatelessWidget { void showRestaurantCardHomeDialog( BuildContext context, List favoriteCardTypes, + void Function(List) updateHomePage, ) { showDialog( context: context, @@ -81,8 +87,7 @@ class CardFavoriteButton extends StatelessWidget { ), ElevatedButton( onPressed: () { - Provider.of(context, listen: false) - .setFavoriteCards( + updateHomePage( favoriteCardTypes + [FavoriteWidgetType.restaurant], ); Navigator.of(context).pop();