From 16e11a2ff518a6c5ce362d38dc137cb54d5c0425 Mon Sep 17 00:00:00 2001 From: davidpkj Date: Sun, 5 Mar 2023 15:03:58 +0100 Subject: Add toastbar to unclickable links on info page --- lib/views/info_view.dart | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'lib/views/info_view.dart') 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 { 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 { 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 { 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 { ); } - _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); } } } -- cgit v1.2.3