From 4c7de14f28857e67f2345ca6e647e6c74a31d328 Mon Sep 17 00:00:00 2001 From: 24bartixx Date: Wed, 11 Dec 2024 11:20:55 +0100 Subject: [PATCH] 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: