Skip to content

Commit

Permalink
Fix implementation and reorganize statements
Browse files Browse the repository at this point in the history
  • Loading branch information
rubuy-74 committed Dec 8, 2023
1 parent e56e915 commit 46de6ed
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions uni/lib/view/restaurant/widgets/restaurant_page_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,22 @@ class CardFavoriteButton extends StatelessWidget {
builder: (context, restaurantProvider) {
final isFavorite =
restaurantProvider.favoriteRestaurants.contains(restaurant.name);
final favoriteCardTypes =
Provider.of<HomePageProvider>(context).favoriteCards;
return IconButton(
icon: isFavorite ? Icon(MdiIcons.heart) : Icon(MdiIcons.heartOutline),
onPressed: () => {
onPressed: () {
restaurantProvider.toggleFavoriteRestaurant(
restaurant.name,
),
);
final favoriteCardTypes =
context.read<HomePageProvider>().favoriteCards;
if (!isFavorite &&
!favoriteCardTypes.contains(FavoriteWidgetType.restaurant))
showRestaurantCardHomeDialog(context, favoriteCardTypes),
!favoriteCardTypes.contains(FavoriteWidgetType.restaurant)) {
showRestaurantCardHomeDialog(context, favoriteCardTypes,
(newFavoriteCards) {
Provider.of<HomePageProvider>(context, listen: false)
.setFavoriteCards(newFavoriteCards);
});
}
},
);
},
Expand All @@ -67,6 +72,7 @@ class CardFavoriteButton extends StatelessWidget {
void showRestaurantCardHomeDialog(
BuildContext context,
List<FavoriteWidgetType> favoriteCardTypes,
void Function(List<FavoriteWidgetType>) updateHomePage,
) {
showDialog<void>(
context: context,
Expand All @@ -81,10 +87,8 @@ class CardFavoriteButton extends StatelessWidget {
),
ElevatedButton(
onPressed: () {
Provider.of<HomePageProvider>(context, listen: false)
.setFavoriteCards(
favoriteCardTypes + [FavoriteWidgetType.restaurant],
);
updateHomePage(
favoriteCardTypes + [FavoriteWidgetType.restaurant],);
Navigator.of(context).pop();
},
child: Text(S.of(context).yes),
Expand Down

0 comments on commit 46de6ed

Please sign in to comment.