6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 3a1610f4
Changed files
.../android/app/src/main/AndroidManifest.xml | 4 ++++ .../lib/hotel_information/components/email.dart | 3 ++- .../components/structured_text.dart | 12 ++--------- comwell_key_app/lib/utils/launch_util.dart | 24 +++++++++++++++++++++- 4 files changed, 31 insertions(+), 12 deletions(-)
Diff
diff --git a/comwell_key_app/android/app/src/main/AndroidManifest.xml b/comwell_key_app/android/app/src/main/AndroidManifest.xml
index 963a9c86..f8a2d868 100644
--- a/comwell_key_app/android/app/src/main/AndroidManifest.xml
+++ b/comwell_key_app/android/app/src/main/AndroidManifest.xml
@@ -19,6 +19,10 @@
<intent>
<action android:name="android.support.customtabs.action.CustomTabsService" />
</intent>
+ <intent>
+ <action android:name="android.intent.action.SENDTO" />
+ <data android:scheme="mailto" />
+ </intent>
</queries>
<application
android:label="@string/app_name"
diff --git a/comwell_key_app/lib/hotel_information/components/email.dart b/comwell_key_app/lib/hotel_information/components/email.dart
index 8c6be29c..1631afa0 100644
--- a/comwell_key_app/lib/hotel_information/components/email.dart
+++ b/comwell_key_app/lib/hotel_information/components/email.dart
@@ -2,6 +2,7 @@ import 'package:comwell_key_app/hotel_information/components/contact_hotel_butto
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
+import 'package:comwell_key_app/utils/launch_util.dart';
class Email extends StatelessWidget {
final String email;
@@ -14,7 +15,7 @@ class Email extends StatelessWidget {
subtitle: email,
iconPath: "assets/icons/ic_send.svg",
onClick: () {
- launchUrl(Uri.parse("mailto:$email"));
+ launchEmail(context, email);
},
);
}
diff --git a/comwell_key_app/lib/hotel_information/components/structured_text.dart b/comwell_key_app/lib/hotel_information/components/structured_text.dart
index e2256b15..aa28690c 100644
--- a/comwell_key_app/lib/hotel_information/components/structured_text.dart
+++ b/comwell_key_app/lib/hotel_information/components/structured_text.dart
@@ -13,6 +13,7 @@ import 'package:comwell_key_app/hotel_information/components/maps_bottom_modal.d
import 'package:comwell_key_app/hotel_information/components/opening_hours.dart';
import 'package:comwell_key_app/hotel_information/components/page_title.dart';
import 'package:comwell_key_app/hotel_information/components/email.dart';
+import 'package:comwell_key_app/utils/launch_util.dart';
class StructuredText extends StatelessWidget {
final List<StructuredTextBlock> blocks;
@@ -53,16 +54,7 @@ class StructuredText extends StatelessWidget {
subtitle: b.email,
iconPath: "assets/icons/ic_send.svg",
onClick: () async {
- final Uri emailUri = Uri.parse("mailto:${b.email}");
- if (await canLaunchUrl(emailUri)) {
- await launchUrl(emailUri, mode: LaunchMode.externalApplication);
- } else {
- if (context.mounted) {
- ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(content: Text("email_launch_error".tr())),
- );
- }
- }
+ await launchEmail(context, b.email, errorMessage: "email_launch_error".tr());
},
),
),
diff --git a/comwell_key_app/lib/utils/launch_util.dart b/comwell_key_app/lib/utils/launch_util.dart
index e66367f6..ee675f27 100644
--- a/comwell_key_app/lib/utils/launch_util.dart
+++ b/comwell_key_app/lib/utils/launch_util.dart
@@ -1,3 +1,4 @@
+import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
Future<void> makePhoneCall(String phoneNumber) async {
@@ -6,4 +7,25 @@ Future<void> makePhoneCall(String phoneNumber) async {
path: phoneNumber,
);
await launchUrl(launchUri);
- }
\ No newline at end of file
+ }
+
+Future<void> launchAppUrl(BuildContext context, Uri uri, {String? errorMessage}) async {
+ debugPrint('Trying to launch: ' + uri.toString());
+ final canLaunch = await canLaunchUrl(uri);
+ debugPrint('canLaunchUrl result: $canLaunch');
+ if (canLaunch) {
+ await launchUrl(uri, mode: LaunchMode.externalApplication);
+ } else {
+ debugPrint('canLaunchUrl returned false for: ' + uri.toString());
+ if (context.mounted) {
+ ScaffoldMessenger.of(context).showSnackBar(
+ SnackBar(content: Text(errorMessage ?? 'Could not open the app.')),
+ );
+ }
+ }
+}
+
+Future<void> launchEmail(BuildContext context, String email, {String? errorMessage}) async {
+ final Uri emailUri = Uri(scheme: 'mailto', path: email);
+ await launchAppUrl(context, emailUri, errorMessage: errorMessage ?? 'Could not open email app.');
+}
\ No newline at end of file