diff options
author | davidpkj <davidpenkow1@gmail.com> | 2023-03-05 15:03:58 +0100 |
---|---|---|
committer | davidpkj <davidpenkow1@gmail.com> | 2023-03-05 15:03:58 +0100 |
commit | 16e11a2ff518a6c5ce362d38dc137cb54d5c0425 (patch) | |
tree | c7580e6f21e4ccdf7e67f4723c960db85660e1a0 /lib/views/info_view.dart | |
parent | ace91d2b7389a7e15827f7e1a11d604659acabfc (diff) |
Add toastbar to unclickable links on info page
Diffstat (limited to 'lib/views/info_view.dart')
-rw-r--r-- | lib/views/info_view.dart | 33 |
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); } } } |