Skip to content

Commit

Permalink
feat: add report button functionality - open email app
Browse files Browse the repository at this point in the history
  • Loading branch information
24bartixx committed Dec 11, 2024
1 parent 4b002c5 commit 4c7de14
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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,
Expand All @@ -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),
),
),
Expand All @@ -35,3 +40,28 @@ class ReportChangeButton extends StatelessWidget {
);
}
}

Future<void> 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,
),
);
}
}
7 changes: 5 additions & 2 deletions lib/l10n/app_pl.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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" : "[email protected]",
"report_change_subject" : "Sugestia zmiany - ToPWR",
"report_change_error_toast_message" : "Nie można otworzyć aplikacji mailowej",
"localization" : "Lokalizacja",
"amenities" : "Udogodnienia",
"surroundings": "Otoczenie",
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 4c7de14

Please sign in to comment.