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 authored and bdmendes committed Dec 8, 2023
1 parent a1937a7 commit 0f0c469
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 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,8 +87,7 @@ class CardFavoriteButton extends StatelessWidget {
),
ElevatedButton(
onPressed: () {
Provider.of<HomePageProvider>(context, listen: false)
.setFavoriteCards(
updateHomePage(
favoriteCardTypes + [FavoriteWidgetType.restaurant],
);
Navigator.of(context).pop();
Expand Down

0 comments on commit 0f0c469

Please sign in to comment.