Skip to content

Commit

Permalink
Implement Restaurant Home Card Dialog (#1036)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdmendes authored Dec 9, 2023
2 parents 7b66528 + 0f0c469 commit 3766f6e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 3 deletions.
2 changes: 2 additions & 0 deletions uni/lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ class MessageLookup extends MessageLookupByLibrary {
"Reference created successfully!"),
"remove": MessageLookupByLibrary.simpleMessage("Delete"),
"report_error": MessageLookupByLibrary.simpleMessage("Report error"),
"restaurant_main_page": MessageLookupByLibrary.simpleMessage(
"Do you want to see your favorite restaurants in the main page?"),
"room": MessageLookupByLibrary.simpleMessage("Room"),
"school_calendar":
MessageLookupByLibrary.simpleMessage("School Calendar"),
Expand Down
2 changes: 2 additions & 0 deletions uni/lib/generated/intl/messages_pt_PT.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ class MessageLookup extends MessageLookupByLibrary {
"Referência criada com sucesso!"),
"remove": MessageLookupByLibrary.simpleMessage("Remover"),
"report_error": MessageLookupByLibrary.simpleMessage("Reportar erro"),
"restaurant_main_page": MessageLookupByLibrary.simpleMessage(
"Queres ver os teus restaurantes favoritos na página principal?"),
"room": MessageLookupByLibrary.simpleMessage("Sala"),
"school_calendar":
MessageLookupByLibrary.simpleMessage("Calendário Escolar"),
Expand Down
10 changes: 10 additions & 0 deletions uni/lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions uni/lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@
"@remove": {},
"report_error": "Report error",
"@report_error": {},
"restaurant_main_page" : "Do you want to see your favorite restaurants in the main page?",
"@restaurant_main_page": {},
"room": "Room",
"@room": {},
"school_calendar": "School Calendar",
Expand Down
2 changes: 2 additions & 0 deletions uni/lib/l10n/intl_pt_PT.arb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@
"@remove": {},
"report_error": "Reportar erro",
"@report_error": {},
"restaurant_main_page" : "Queres ver os teus restaurantes favoritos na página principal?",
"@restaurant_main_page": {},
"room": "Sala",
"@room": {},
"school_calendar": "Calendário Escolar",
Expand Down
52 changes: 49 additions & 3 deletions uni/lib/view/restaurant/widgets/restaurant_page_card.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'package:flutter/material.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:provider/provider.dart';
import 'package:uni/generated/l10n.dart';
import 'package:uni/model/entities/restaurant.dart';
import 'package:uni/model/providers/lazy/home_page_provider.dart';
import 'package:uni/model/providers/lazy/restaurant_provider.dart';
import 'package:uni/utils/favorite_widget_type.dart';
import 'package:uni/view/common_widgets/generic_card.dart';
import 'package:uni/view/lazy_consumer.dart';

Expand Down Expand Up @@ -45,11 +49,53 @@ class CardFavoriteButton extends StatelessWidget {
restaurantProvider.favoriteRestaurants.contains(restaurant.name);
return IconButton(
icon: isFavorite ? Icon(MdiIcons.heart) : Icon(MdiIcons.heartOutline),
onPressed: () => restaurantProvider.toggleFavoriteRestaurant(
restaurant.name,
),
onPressed: () {
restaurantProvider.toggleFavoriteRestaurant(
restaurant.name,
);
final favoriteCardTypes =
context.read<HomePageProvider>().favoriteCards;
if (!isFavorite &&
!favoriteCardTypes.contains(FavoriteWidgetType.restaurant)) {
showRestaurantCardHomeDialog(context, favoriteCardTypes,
(newFavoriteCards) {
Provider.of<HomePageProvider>(context, listen: false)
.setFavoriteCards(newFavoriteCards);
});
}
},
);
},
);
}

void showRestaurantCardHomeDialog(
BuildContext context,
List<FavoriteWidgetType> favoriteCardTypes,
void Function(List<FavoriteWidgetType>) updateHomePage,
) {
showDialog<void>(
context: context,
builder: (context) => AlertDialog(
title: Text(S.of(context).restaurant_main_page),
actions: <Widget>[
ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(S.of(context).no),
),
ElevatedButton(
onPressed: () {
updateHomePage(
favoriteCardTypes + [FavoriteWidgetType.restaurant],
);
Navigator.of(context).pop();
},
child: Text(S.of(context).yes),
),
],
),
);
}
}

0 comments on commit 3766f6e

Please sign in to comment.