From 4c7de14f28857e67f2345ca6e647e6c74a31d328 Mon Sep 17 00:00:00 2001 From: 24bartixx Date: Wed, 11 Dec 2024 11:20:55 +0100 Subject: [PATCH 01/11] feat: add report button functionality - open email app --- .../widgets/report_change_button.dart | 38 +++++++++++++++++-- lib/l10n/app_pl.arb | 7 +++- pubspec.yaml | 1 + 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart b/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart index 623d5518..1cfcc402 100644 --- a/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart +++ b/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart @@ -1,4 +1,8 @@ +import "dart:async"; + import "package:flutter/material.dart"; +import "package:fluttertoast/fluttertoast.dart"; +import "package:url_launcher/url_launcher.dart"; import "../../../../../config/ui_config.dart"; import "../../../../../theme/app_theme.dart"; @@ -11,11 +15,12 @@ class ReportChangeButton extends StatelessWidget { padding: AppWidgetsConfig.paddingMedium, child: Column( children: [ - Text(context.localize.change_report_title), + Text(context.localize.report_change_title), const SizedBox(height: 8), ElevatedButton( - // TODO(Bartosh): handle action - onPressed: () {}, + onPressed: () async { + await openEmailApp(context); + }, style: ElevatedButton.styleFrom( backgroundColor: context.colorTheme.blueAzure, padding: AppWidgetsConfig.paddingMedium, @@ -26,7 +31,7 @@ class ReportChangeButton extends StatelessWidget { ), ), child: Text( - context.localize.change_report_button, + context.localize.report_change_button, style: TextStyle(color: context.colorTheme.whiteSoap), ), ), @@ -35,3 +40,28 @@ class ReportChangeButton extends StatelessWidget { ); } } + +Future openEmailApp(BuildContext context) async { + final errorMessageToast = context.localize.report_change_error_toast_message; + final backgroundColorToast = context.colorTheme.blackMirage; + + final Uri emailUrl = Uri( + scheme: "mailto", + path: context.localize.report_change_email, + query: + "subject=${Uri.encodeComponent(context.localize.report_change_subject)}", + ); + + debugPrint("Email url: $emailUrl"); + + if (!await launchUrl(emailUrl)) { + unawaited( + Fluttertoast.showToast( + msg: errorMessageToast, + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.TOP, + backgroundColor: backgroundColorToast, + ), + ); + } +} diff --git a/lib/l10n/app_pl.arb b/lib/l10n/app_pl.arb index d167e43c..d82c95c1 100644 --- a/lib/l10n/app_pl.arb +++ b/lib/l10n/app_pl.arb @@ -151,8 +151,11 @@ "about_the_app": "O aplikacji", "other_view" : "Inne", "map" : "Mapa", - "change_report_title" : "Coś się zmieniło?", - "change_report_button" : "Zgłoś zmianę", + "report_change_title" : "Coś się zmieniło?", + "report_change_button" : "Zgłoś zmianę", + "report_change_email" : "kn.solvro@pwr.edu.pl", + "report_change_subject" : "Sugestia zmiany - ToPWR", + "report_change_error_toast_message" : "Nie można otworzyć aplikacji mailowej", "localization" : "Lokalizacja", "amenities" : "Udogodnienia", "surroundings": "Otoczenie", diff --git a/pubspec.yaml b/pubspec.yaml index b2dea573..19ddbfea 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -89,6 +89,7 @@ dependencies: upgrader: ^11.3.0 in_app_review: ^2.0.9 flutter_map_animations: ^0.7.1 + fluttertoast: ^8.2.8 dev_dependencies: flutter_test: From de3a96980341cf612595630e62f07f65184de52e Mon Sep 17 00:00:00 2001 From: 24bartixx Date: Wed, 11 Dec 2024 11:47:04 +0100 Subject: [PATCH 02/11] fix: add horizontal padding --- lib/config/ui_config.dart | 1 + .../digital_guide_data_source_link.dart | 40 ++++++++++--------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/config/ui_config.dart b/lib/config/ui_config.dart index 91891a1b..434d1c1c 100644 --- a/lib/config/ui_config.dart +++ b/lib/config/ui_config.dart @@ -215,6 +215,7 @@ abstract class DigitalGuideConfig { static const heightSmall = 8.0; static const heightBig = 24.0; static const heightHuge = 48.0; + static const paddingMedium = 16.0; } abstract class AlertDialogConfig { diff --git a/lib/features/digital_guide_view/general_info/presentation/widgets/digital_guide_data_source_link.dart b/lib/features/digital_guide_view/general_info/presentation/widgets/digital_guide_data_source_link.dart index f3a19e5e..57eba9b8 100644 --- a/lib/features/digital_guide_view/general_info/presentation/widgets/digital_guide_data_source_link.dart +++ b/lib/features/digital_guide_view/general_info/presentation/widgets/digital_guide_data_source_link.dart @@ -1,32 +1,36 @@ import "package:flutter/widgets.dart"; import "package:flutter_riverpod/flutter_riverpod.dart"; +import "../../../../../config/ui_config.dart"; import "../../../../../theme/app_theme.dart"; import "../../../../../utils/context_extensions.dart"; class DigitalGuideDataSourceLink extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - return Text.rich( - TextSpan( - text: "${context.localize.data_come_from_website}: ", - style: const TextStyle( - fontWeight: FontWeight.bold, - ), - children: [ - TextSpan( - text: context.localize.digital_guide_website, - style: context.textTheme.bodyOrange.copyWith( - decoration: TextDecoration.underline, - decorationColor: context.colorTheme.orangePomegranade, - fontWeight: FontWeight.bold, - ), - // TODO(Bartosh): on tap url handling -> webbrowser launch + return Padding( + padding: const EdgeInsets.symmetric(horizontal: DigitalGuideConfig.paddingMedium), + child: Text.rich( + TextSpan( + text: "${context.localize.data_come_from_website}: ", + style: const TextStyle( + fontWeight: FontWeight.bold, ), - ], + children: [ + TextSpan( + text: context.localize.digital_guide_website, + style: context.textTheme.bodyOrange.copyWith( + decoration: TextDecoration.underline, + decorationColor: context.colorTheme.orangePomegranade, + fontWeight: FontWeight.bold, + ), + // TODO(Bartosh): on tap url handling -> webbrowser launch + ), + ], + ), + textAlign: TextAlign.center, + style: context.textTheme.body, ), - textAlign: TextAlign.center, - style: context.textTheme.body, ); } } From f794ec36a65c9dcb4057faf959aa35653ce6679b Mon Sep 17 00:00:00 2001 From: 24bartixx Date: Wed, 11 Dec 2024 12:12:47 +0100 Subject: [PATCH 03/11] fix: padding --- .../presentation/widgets/digital_guide_data_source_link.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/features/digital_guide_view/general_info/presentation/widgets/digital_guide_data_source_link.dart b/lib/features/digital_guide_view/general_info/presentation/widgets/digital_guide_data_source_link.dart index 57eba9b8..7a1e440c 100644 --- a/lib/features/digital_guide_view/general_info/presentation/widgets/digital_guide_data_source_link.dart +++ b/lib/features/digital_guide_view/general_info/presentation/widgets/digital_guide_data_source_link.dart @@ -9,7 +9,8 @@ class DigitalGuideDataSourceLink extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { return Padding( - padding: const EdgeInsets.symmetric(horizontal: DigitalGuideConfig.paddingMedium), + padding: const EdgeInsets.symmetric( + horizontal: DigitalGuideConfig.paddingMedium,), child: Text.rich( TextSpan( text: "${context.localize.data_come_from_website}: ", From 4068d6b8e40f3bf22fa1664a25e1233c629c4287 Mon Sep 17 00:00:00 2001 From: 24bartixx Date: Wed, 11 Dec 2024 13:14:15 +0100 Subject: [PATCH 04/11] fix: toast --- .../presentation/widgets/digital_guide_data_source_link.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/features/digital_guide_view/general_info/presentation/widgets/digital_guide_data_source_link.dart b/lib/features/digital_guide_view/general_info/presentation/widgets/digital_guide_data_source_link.dart index 7a1e440c..4bcf21ca 100644 --- a/lib/features/digital_guide_view/general_info/presentation/widgets/digital_guide_data_source_link.dart +++ b/lib/features/digital_guide_view/general_info/presentation/widgets/digital_guide_data_source_link.dart @@ -10,7 +10,8 @@ class DigitalGuideDataSourceLink extends ConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { return Padding( padding: const EdgeInsets.symmetric( - horizontal: DigitalGuideConfig.paddingMedium,), + horizontal: DigitalGuideConfig.paddingMedium, + ), child: Text.rich( TextSpan( text: "${context.localize.data_come_from_website}: ", From ea03eba53d4deeb50f43ee386016c26ced12ba95 Mon Sep 17 00:00:00 2001 From: 24bartixx Date: Wed, 11 Dec 2024 14:29:40 +0100 Subject: [PATCH 05/11] fix: adjsut toast color and gravity --- .../presentation/widgets/report_change_button.dart | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart b/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart index 1cfcc402..0ea3d174 100644 --- a/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart +++ b/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart @@ -42,8 +42,10 @@ class ReportChangeButton extends StatelessWidget { } Future openEmailApp(BuildContext context) async { + final errorMessageToast = context.localize.report_change_error_toast_message; - final backgroundColorToast = context.colorTheme.blackMirage; + final backgroundColorToast = context.colorTheme.greyLight; + final textColorToast = context.colorTheme.blackMirage; final Uri emailUrl = Uri( scheme: "mailto", @@ -52,15 +54,14 @@ Future openEmailApp(BuildContext context) async { "subject=${Uri.encodeComponent(context.localize.report_change_subject)}", ); - debugPrint("Email url: $emailUrl"); - - if (!await launchUrl(emailUrl)) { + if (await canLaunchUrl(emailUrl) && !await launchUrl(emailUrl)) { unawaited( Fluttertoast.showToast( msg: errorMessageToast, toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.TOP, + gravity: ToastGravity.BOTTOM, backgroundColor: backgroundColorToast, + textColor: textColorToast, ), ); } From 2ca2955c8b7b72c06e9e148249bd3a0aad09616d Mon Sep 17 00:00:00 2001 From: 24bartixx Date: Wed, 11 Dec 2024 14:38:31 +0100 Subject: [PATCH 06/11] fix: lint rules --- .../general_info/presentation/widgets/report_change_button.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart b/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart index 0ea3d174..af81e682 100644 --- a/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart +++ b/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart @@ -42,7 +42,6 @@ class ReportChangeButton extends StatelessWidget { } Future openEmailApp(BuildContext context) async { - final errorMessageToast = context.localize.report_change_error_toast_message; final backgroundColorToast = context.colorTheme.greyLight; final textColorToast = context.colorTheme.blackMirage; From d0e1fe5688d49c04d319fb8fb7f57bf58e51fab6 Mon Sep 17 00:00:00 2001 From: 24bartixx Date: Wed, 11 Dec 2024 18:11:19 +0100 Subject: [PATCH 07/11] refractor: utilize existing extension --- .../widgets/report_change_button.dart | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart b/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart index af81e682..60668fd4 100644 --- a/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart +++ b/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart @@ -1,16 +1,17 @@ import "dart:async"; import "package:flutter/material.dart"; +import "package:flutter_riverpod/flutter_riverpod.dart"; import "package:fluttertoast/fluttertoast.dart"; -import "package:url_launcher/url_launcher.dart"; import "../../../../../config/ui_config.dart"; import "../../../../../theme/app_theme.dart"; import "../../../../../utils/context_extensions.dart"; +import "../../../../../utils/launch_url_util.dart"; -class ReportChangeButton extends StatelessWidget { +class ReportChangeButton extends ConsumerWidget { @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { return Padding( padding: AppWidgetsConfig.paddingMedium, child: Column( @@ -19,7 +20,7 @@ class ReportChangeButton extends StatelessWidget { const SizedBox(height: 8), ElevatedButton( onPressed: () async { - await openEmailApp(context); + await openEmailApp(context, ref); }, style: ElevatedButton.styleFrom( backgroundColor: context.colorTheme.blueAzure, @@ -41,19 +42,14 @@ class ReportChangeButton extends StatelessWidget { } } -Future openEmailApp(BuildContext context) async { +Future openEmailApp(BuildContext context, WidgetRef ref) async { final errorMessageToast = context.localize.report_change_error_toast_message; final backgroundColorToast = context.colorTheme.greyLight; final textColorToast = context.colorTheme.blackMirage; - final Uri emailUrl = Uri( - scheme: "mailto", - path: context.localize.report_change_email, - query: - "subject=${Uri.encodeComponent(context.localize.report_change_subject)}", - ); - - if (await canLaunchUrl(emailUrl) && !await launchUrl(emailUrl)) { + if (await ref.launch( + "mailto:${context.localize.report_change_email}?subject=${Uri.encodeComponent(context.localize.report_change_subject)}", + )) { unawaited( Fluttertoast.showToast( msg: errorMessageToast, From 518738dc826d321c513b7f26bff084b1fe2c0ca0 Mon Sep 17 00:00:00 2001 From: 24bartixx Date: Wed, 11 Dec 2024 19:41:11 +0100 Subject: [PATCH 08/11] refractor: move function that opens email app to a lambda expression --- .../widgets/report_change_button.dart | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart b/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart index 60668fd4..1225a351 100644 --- a/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart +++ b/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart @@ -20,7 +20,24 @@ class ReportChangeButton extends ConsumerWidget { const SizedBox(height: 8), ElevatedButton( onPressed: () async { - await openEmailApp(context, ref); + final errorMessageToast = + context.localize.report_change_error_toast_message; + final backgroundColorToast = context.colorTheme.greyLight; + final textColorToast = context.colorTheme.blackMirage; + + if (!await ref.launch( + "mailto:${context.localize.report_change_email}?subject=${Uri.encodeComponent(context.localize.report_change_subject)}", + )) { + unawaited( + Fluttertoast.showToast( + msg: errorMessageToast, + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + backgroundColor: backgroundColorToast, + textColor: textColorToast, + ), + ); + } }, style: ElevatedButton.styleFrom( backgroundColor: context.colorTheme.blueAzure, @@ -41,23 +58,3 @@ class ReportChangeButton extends ConsumerWidget { ); } } - -Future openEmailApp(BuildContext context, WidgetRef ref) async { - final errorMessageToast = context.localize.report_change_error_toast_message; - final backgroundColorToast = context.colorTheme.greyLight; - final textColorToast = context.colorTheme.blackMirage; - - if (await ref.launch( - "mailto:${context.localize.report_change_email}?subject=${Uri.encodeComponent(context.localize.report_change_subject)}", - )) { - unawaited( - Fluttertoast.showToast( - msg: errorMessageToast, - toastLength: Toast.LENGTH_LONG, - gravity: ToastGravity.BOTTOM, - backgroundColor: backgroundColorToast, - textColor: textColorToast, - ), - ); - } -} From b68d72dec26375e2b3368274f8a4222fef7f182c Mon Sep 17 00:00:00 2001 From: 24bartixx Date: Wed, 11 Dec 2024 19:52:28 +0100 Subject: [PATCH 09/11] feat: handle digital guide source info tap --- .../widgets/digital_guide_data_source_link.dart | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/features/digital_guide_view/general_info/presentation/widgets/digital_guide_data_source_link.dart b/lib/features/digital_guide_view/general_info/presentation/widgets/digital_guide_data_source_link.dart index 4bcf21ca..e91e8da9 100644 --- a/lib/features/digital_guide_view/general_info/presentation/widgets/digital_guide_data_source_link.dart +++ b/lib/features/digital_guide_view/general_info/presentation/widgets/digital_guide_data_source_link.dart @@ -1,9 +1,11 @@ +import "package:flutter/gestures.dart"; import "package:flutter/widgets.dart"; import "package:flutter_riverpod/flutter_riverpod.dart"; import "../../../../../config/ui_config.dart"; import "../../../../../theme/app_theme.dart"; import "../../../../../utils/context_extensions.dart"; +import "../../../../../utils/launch_url_util.dart"; class DigitalGuideDataSourceLink extends ConsumerWidget { @override @@ -26,7 +28,13 @@ class DigitalGuideDataSourceLink extends ConsumerWidget { decorationColor: context.colorTheme.orangePomegranade, fontWeight: FontWeight.bold, ), - // TODO(Bartosh): on tap url handling -> webbrowser launch + recognizer: TapGestureRecognizer() + ..onTap = () async { + await ref.launch( + context.localize.digital_guide_website + .replaceAll("www.", "https://"), + ); + }, ), ], ), From d206c1b715d55663bb259c30cc58e3b1db08553d Mon Sep 17 00:00:00 2001 From: 24bartixx Date: Wed, 11 Dec 2024 20:09:55 +0100 Subject: [PATCH 10/11] refractor: move emailUrl string from a direct declaration to a final variable --- .../presentation/widgets/report_change_button.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart b/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart index 1225a351..0632b83f 100644 --- a/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart +++ b/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart @@ -25,8 +25,10 @@ class ReportChangeButton extends ConsumerWidget { final backgroundColorToast = context.colorTheme.greyLight; final textColorToast = context.colorTheme.blackMirage; + final emailUrl = "mailto:${context.localize.report_change_email}?subject=${Uri.encodeComponent(context.localize.report_change_subject)}"; + if (!await ref.launch( - "mailto:${context.localize.report_change_email}?subject=${Uri.encodeComponent(context.localize.report_change_subject)}", + emailUrl, )) { unawaited( Fluttertoast.showToast( From 688b30f001e4d91e1b9edf22bab4bddfa787f174 Mon Sep 17 00:00:00 2001 From: 24bartixx Date: Wed, 11 Dec 2024 20:10:55 +0100 Subject: [PATCH 11/11] fix: formatting --- .../presentation/widgets/report_change_button.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart b/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart index 0632b83f..06deadf5 100644 --- a/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart +++ b/lib/features/digital_guide_view/general_info/presentation/widgets/report_change_button.dart @@ -25,7 +25,8 @@ class ReportChangeButton extends ConsumerWidget { final backgroundColorToast = context.colorTheme.greyLight; final textColorToast = context.colorTheme.blackMirage; - final emailUrl = "mailto:${context.localize.report_change_email}?subject=${Uri.encodeComponent(context.localize.report_change_subject)}"; + final emailUrl = + "mailto:${context.localize.report_change_email}?subject=${Uri.encodeComponent(context.localize.report_change_subject)}"; if (!await ref.launch( emailUrl,