From 394d761f4065112b8085bff47d8def1e88158a2f Mon Sep 17 00:00:00 2001 From: Vadim Date: Mon, 8 May 2023 16:45:24 +0200 Subject: [PATCH] added error toast --- android/app/src/main/AndroidManifest.xml | 8 ++++ lib/l10n/intl_en.arb | 2 + lib/l10n/intl_fr.arb | 2 + lib/l10n/intl_ru.arb | 2 + .../widget_list_tile_write_email.dart | 37 +++++++++++++++++-- pubspec.yaml | 1 + 6 files changed, 48 insertions(+), 4 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 5271758..6dba1a5 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -35,6 +35,14 @@ android:value="2" /> + + + + + + + + diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 9bf3139..c404d33 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -70,6 +70,8 @@ "sourceCode": "Source code", "reportIssue": "Report an issue", "writeEmail": "Write an email", + "youDontHaveMailApp": "You don't have any mail app installed.", + "copyEmail": "Copy email", "version": "Version", "versionNumber": "{version} ({buildNumber})", "@versionNumber": { diff --git a/lib/l10n/intl_fr.arb b/lib/l10n/intl_fr.arb index 1881e66..5102a59 100644 --- a/lib/l10n/intl_fr.arb +++ b/lib/l10n/intl_fr.arb @@ -70,6 +70,8 @@ "sourceCode": "Code source", "reportIssue": "Rapporter un problème", "writeEmail": "Écrire un email", + "youDontHaveMailApp": "Vous n'avez installé aucune application de messagerie.", + "copyEmail": "Copier un e-mail", "version": "Version", "versionNumber": "{version} ({buildNumber})", "@versionNumber": { diff --git a/lib/l10n/intl_ru.arb b/lib/l10n/intl_ru.arb index 13be45b..ca746dd 100644 --- a/lib/l10n/intl_ru.arb +++ b/lib/l10n/intl_ru.arb @@ -70,6 +70,8 @@ "sourceCode": "Исходный код", "reportIssue": "Сообщить о проблеме", "writeEmail": "Написать на почту", + "youDontHaveMailApp": "У вас не установлено почтовое приложение.", + "copyEmail": "Скопировать адрес", "version": "Версия", "versionNumber": "{version} ({buildNumber})", "@versionNumber": { diff --git a/lib/screens/settings/components/about/components/write_email/widget_list_tile_write_email.dart b/lib/screens/settings/components/about/components/write_email/widget_list_tile_write_email.dart index 76a4008..db06f34 100644 --- a/lib/screens/settings/components/about/components/write_email/widget_list_tile_write_email.dart +++ b/lib/screens/settings/components/about/components/write_email/widget_list_tile_write_email.dart @@ -1,6 +1,8 @@ +import 'package:clipboard/clipboard.dart'; import 'package:flutter/material.dart'; import 'package:lightmeter/environment.dart'; import 'package:lightmeter/generated/l10n.dart'; +import 'package:lightmeter/res/dimens.dart'; import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -13,11 +15,38 @@ class WriteEmailListTile extends StatelessWidget { leading: const Icon(Icons.email), title: Text(S.of(context).writeEmail), onTap: () { - launchUrl( - Uri.parse('mailto:${context.read().contactEmail}?subject=M3 Lightmeter'), - mode: LaunchMode.externalApplication, - ); + final email = context.read().contactEmail; + final mailToUrl = Uri.parse('mailto:$email?subject=M3 Lightmeter'); + canLaunchUrl(mailToUrl).then((canLaunch) { + if (canLaunch) { + launchUrl( + mailToUrl, + mode: LaunchMode.externalApplication, + ); + } else { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(S.of(context).youDontHaveMailApp), + behavior: SnackBarBehavior.floating, + action: SnackBarAction( + label: S.of(context).copyEmail, + onPressed: () { + FlutterClipboard.copy(email).then((_) { + ScaffoldMessenger.of(context).clearSnackBars(); + }); + }, + ), + ), + ); + } + }); }, ); } + + void _copyEmail(BuildContext context) { + FlutterClipboard.copy(context.read().contactEmail).then((_) { + ScaffoldMessenger.of(context).clearSnackBars(); + }); + } } diff --git a/pubspec.yaml b/pubspec.yaml index e2b3f3a..cf4ba86 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,6 +9,7 @@ environment: dependencies: app_settings: 4.2.0 camera: 0.10.0+4 + clipboard: 0.1.3 exif: 3.1.2 dynamic_color: 1.5.4 firebase_core: 2.11.0