aboutsummaryrefslogtreecommitdiff
path: root/lib/views
diff options
context:
space:
mode:
Diffstat (limited to 'lib/views')
-rw-r--r--lib/views/info_view.dart33
1 files changed, 24 insertions, 9 deletions
diff --git a/lib/views/info_view.dart b/lib/views/info_view.dart
index 0d0897d..fbe522a 100644
--- a/lib/views/info_view.dart
+++ b/lib/views/info_view.dart
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:kulinar_app/constants.dart';
import 'package:kulinar_app/widgets/custom_drawer_widget.dart';
+import 'package:kulinar_app/widgets/toastbar_widget.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
@@ -44,7 +45,7 @@ class InfoViewState extends State<InfoView> {
trailing: IconButton(
icon: const Icon(Icons.north_east_rounded),
onPressed: () {
- _launchURL(Uri.parse(websiteURL));
+ _launchLink(websiteURL, context);
},
),
),
@@ -54,7 +55,7 @@ class InfoViewState extends State<InfoView> {
trailing: IconButton(
icon: const Icon(Icons.north_east_rounded),
onPressed: () {
- _launchURL(Uri.parse(sourceCodeURL));
+ _launchLink(sourceCodeURL, context);
},
),
),
@@ -64,7 +65,7 @@ class InfoViewState extends State<InfoView> {
trailing: IconButton(
icon: const Icon(Icons.north_east_rounded),
onPressed: () {
- _launchURL(Uri.parse(privacyNoticeURL));
+ _launchLink(privacyNoticeURL, context);
},
),
),
@@ -91,12 +92,26 @@ class InfoViewState extends State<InfoView> {
);
}
- _launchURL(Uri url) async {
- if (await canLaunchUrl(url)) {
- await launchUrl(url, mode: LaunchMode.externalApplication);
- } else {
- debugPrint("Could not launch $url");
- // TODO: maybe add toastbar
+ cantOpenLink(var why, BuildContext context) {
+ // TODO: translation
+ ToastBar.showToastBar(context, "Could not open link", actionLabel: "");
+
+ debugPrint("Could not open $why");
+ }
+
+ _launchLink(String link, BuildContext context) async {
+ Uri uri = Uri();
+
+ try {
+ uri = Uri.parse(link);
+
+ if (await canLaunchUrl(uri)) {
+ await launchUrl(uri, mode: LaunchMode.externalApplication);
+ } else {
+ throw link;
+ }
+ } catch (e) {
+ cantOpenLink(e, context);
}
}
}