From bb56ef17a74bc62d1396f8ac05a9c536195dfc8f Mon Sep 17 00:00:00 2001 From: rubuy-74 Date: Sat, 18 Nov 2023 21:22:50 +0000 Subject: [PATCH 1/3] Implement Restaurant Home Card Dialog --- uni/lib/generated/intl/messages_en.dart | 2 + uni/lib/generated/intl/messages_pt_PT.dart | 2 + uni/lib/generated/l10n.dart | 10 ++++ uni/lib/l10n/intl_en.arb | 2 + uni/lib/l10n/intl_pt_PT.arb | 2 + .../widgets/restaurant_page_card.dart | 47 +++++++++++++++++-- 6 files changed, 62 insertions(+), 3 deletions(-) diff --git a/uni/lib/generated/intl/messages_en.dart b/uni/lib/generated/intl/messages_en.dart index 112516f05..2256f8e76 100644 --- a/uni/lib/generated/intl/messages_en.dart +++ b/uni/lib/generated/intl/messages_en.dart @@ -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"), diff --git a/uni/lib/generated/intl/messages_pt_PT.dart b/uni/lib/generated/intl/messages_pt_PT.dart index 68a173ffe..4e7a23288 100644 --- a/uni/lib/generated/intl/messages_pt_PT.dart +++ b/uni/lib/generated/intl/messages_pt_PT.dart @@ -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"), diff --git a/uni/lib/generated/l10n.dart b/uni/lib/generated/l10n.dart index 936259b3e..c73c45a2d 100644 --- a/uni/lib/generated/l10n.dart +++ b/uni/lib/generated/l10n.dart @@ -1158,6 +1158,16 @@ class S { ); } + /// `Do you want to see your favorite restaurants in the main page?` + String get restaurant_main_page { + return Intl.message( + 'Do you want to see your favorite restaurants in the main page?', + name: 'restaurant_main_page', + desc: '', + args: [], + ); + } + /// `Room` String get room { return Intl.message( diff --git a/uni/lib/l10n/intl_en.arb b/uni/lib/l10n/intl_en.arb index b1d6be897..c1e22210e 100644 --- a/uni/lib/l10n/intl_en.arb +++ b/uni/lib/l10n/intl_en.arb @@ -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", diff --git a/uni/lib/l10n/intl_pt_PT.arb b/uni/lib/l10n/intl_pt_PT.arb index 4315ac0af..26cef1c70 100644 --- a/uni/lib/l10n/intl_pt_PT.arb +++ b/uni/lib/l10n/intl_pt_PT.arb @@ -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", diff --git a/uni/lib/view/restaurant/widgets/restaurant_page_card.dart b/uni/lib/view/restaurant/widgets/restaurant_page_card.dart index d02d616aa..cd6ba0381 100644 --- a/uni/lib/view/restaurant/widgets/restaurant_page_card.dart +++ b/uni/lib/view/restaurant/widgets/restaurant_page_card.dart @@ -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'; @@ -43,13 +47,50 @@ 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: () => restaurantProvider.toggleFavoriteRestaurant( - restaurant.name, - ), + onPressed: () => { + restaurantProvider.toggleFavoriteRestaurant( + restaurant.name, + ), + if (!isFavorite && + !favoriteCardTypes.contains(FavoriteWidgetType.restaurant) && + restaurantProvider.favoriteRestaurants.length < 2) + showRestaurantCardHomeDialog(context, favoriteCardTypes), + }, ); }, ); } + + void showRestaurantCardHomeDialog( + BuildContext context, + List favoriteCardTypes, + ) { + showDialog( + context: context, + builder: (context) => AlertDialog( + title: Text(S.of(context).restaurant_main_page), + actions: [ + ElevatedButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: Text(S.of(context).no), + ), + ElevatedButton( + onPressed: () { + favoriteCardTypes.add(FavoriteWidgetType.restaurant); + Provider.of(context, listen: false) + .setFavoriteCards(favoriteCardTypes); + Navigator.of(context).pop(); + }, + child: Text(S.of(context).yes), + ), + ], + ), + ); + } } From a1937a7198c9278b97dff2023d1508c2c316f762 Mon Sep 17 00:00:00 2001 From: rubuy-74 Date: Thu, 7 Dec 2023 11:15:32 +0000 Subject: [PATCH 2/3] Simplify some statements --- uni/lib/view/restaurant/widgets/restaurant_page_card.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/uni/lib/view/restaurant/widgets/restaurant_page_card.dart b/uni/lib/view/restaurant/widgets/restaurant_page_card.dart index cd6ba0381..7b919d8ec 100644 --- a/uni/lib/view/restaurant/widgets/restaurant_page_card.dart +++ b/uni/lib/view/restaurant/widgets/restaurant_page_card.dart @@ -56,8 +56,7 @@ class CardFavoriteButton extends StatelessWidget { restaurant.name, ), if (!isFavorite && - !favoriteCardTypes.contains(FavoriteWidgetType.restaurant) && - restaurantProvider.favoriteRestaurants.length < 2) + !favoriteCardTypes.contains(FavoriteWidgetType.restaurant)) showRestaurantCardHomeDialog(context, favoriteCardTypes), }, ); @@ -82,9 +81,10 @@ class CardFavoriteButton extends StatelessWidget { ), ElevatedButton( onPressed: () { - favoriteCardTypes.add(FavoriteWidgetType.restaurant); Provider.of(context, listen: false) - .setFavoriteCards(favoriteCardTypes); + .setFavoriteCards( + favoriteCardTypes + [FavoriteWidgetType.restaurant], + ); Navigator.of(context).pop(); }, child: Text(S.of(context).yes), From 0f0c4695ed55067651571f1d85f7201fd5713f96 Mon Sep 17 00:00:00 2001 From: rubuy-74 Date: Fri, 8 Dec 2023 18:47:15 +0000 Subject: [PATCH 3/3] 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();