From bf6608d5767572c5f733fab227d38b1140998132 Mon Sep 17 00:00:00 2001 From: Lea Date: Sun, 5 Feb 2023 16:00:10 +0100 Subject: [PATCH] Add feedback button to popup menu Closes #10 --- lib/main.dart | 8 +++++++ lib/pages/article.dart | 48 ++++++------------------------------------ lib/util.dart | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 42 deletions(-) create mode 100644 lib/util.dart diff --git a/lib/main.dart b/lib/main.dart index d24a241..f9713e6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:feet/notifications/tasks.dart'; +import 'package:feet/util.dart'; import 'package:feet/widgets/centered_page_hint.dart'; import 'package:feet/widgets/filter_menu.dart'; import 'package:feet/widgets/homepage_post.dart'; @@ -285,6 +286,13 @@ class _MyHomePageState extends State { ); }, ), + PopupMenuItem( + value: "feedback", + child: const Text("Feedback"), + onTap: () async { + await openUrl(context, "https://git.amogus.cloud/Lea/feet/issues"); + }, + ), ]), ], ), diff --git a/lib/pages/article.dart b/lib/pages/article.dart index d85297c..a43ed5c 100644 --- a/lib/pages/article.dart +++ b/lib/pages/article.dart @@ -1,11 +1,10 @@ import 'package:feet/api/api.dart'; import 'package:feet/pages/image_view.dart'; +import 'package:feet/util.dart'; import 'package:feet/widgets/homepage_post.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; import 'package:flutter_html/flutter_html.dart'; import 'package:share_plus/share_plus.dart'; -import 'package:url_launcher/url_launcher.dart'; class ArticlePage extends StatefulWidget { final Item article; @@ -23,11 +22,9 @@ class _ArticlePageState extends State { title: Text(widget.article.title), content: Text( // The dart formatter insists of writing this like this - 'By ${widget.article.author.isEmpty ? '(Unknown author)' : widget.article.author}\nPublished on ${formatDate(widget.article.createdOnTime)}${debugInfo - ? '\nID: ${widget.article.id}\n' + 'By ${widget.article.author.isEmpty ? '(Unknown author)' : widget.article.author}\nPublished on ${formatDate(widget.article.createdOnTime)}${debugInfo ? '\nID: ${widget.article.id}\n' 'Is read: ${widget.article.isRead ? 'Yes' : 'No'}\n' - 'Is saved: ${widget.article.isSaved ? 'Yes' : 'No'}' - : ''}', + 'Is saved: ${widget.article.isSaved ? 'Yes' : 'No'}' : ''}', ), actions: debugInfo ? [] @@ -63,41 +60,7 @@ class _ArticlePageState extends State { itemBuilder: (context) => [ PopupMenuItem( onTap: () async { - try { - if (await canLaunchUrl(Uri.parse(widget.article.url))) { - await launchUrl( - Uri.parse(widget.article.url), - mode: LaunchMode.externalApplication, - ); - } else { - throw 'No application available to open URL'; - } - } catch (e) { - showDialog( - context: context, - builder: (context) => AlertDialog( - title: const Text('Cannot open this URL'), - content: Text(e.toString()), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); - Clipboard.setData( - ClipboardData( - text: widget.article.url, - ), - ); - }, - child: const Text('Copy URL'), - ), - TextButton( - onPressed: () => Navigator.of(context).pop(), - child: const Text('Got it!'), - ), - ], - ), - ); - } + await openUrl(context, widget.article.url); }, value: 'open_in_browser', child: const Text('Open in browser'), @@ -113,7 +76,8 @@ class _ArticlePageState extends State { child: SelectionArea( child: Html( data: widget.article.html, - onImageTap: (url, ctx, attributes, element) => Navigator.of(context).push( + onImageTap: (url, ctx, attributes, element) => + Navigator.of(context).push( PageRouteBuilder( opaque: false, pageBuilder: (context, _, __) => ImageView(url: url!), diff --git a/lib/util.dart b/lib/util.dart new file mode 100644 index 0000000..1695e53 --- /dev/null +++ b/lib/util.dart @@ -0,0 +1,41 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:url_launcher/url_launcher.dart'; + +Future openUrl(BuildContext context, String url) async { + try { + if (await canLaunchUrl(Uri.parse(url))) { + await launchUrl( + Uri.parse(url), + mode: LaunchMode.externalApplication, + ); + } else { + throw 'No application available to open URL'; + } + } catch (e) { + showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text('Cannot open this URL'), + content: Text(e.toString()), + actions: [ + TextButton( + onPressed: () { + Navigator.of(context).pop(); + Clipboard.setData( + ClipboardData( + text: url, + ), + ); + }, + child: const Text('Copy URL'), + ), + TextButton( + onPressed: () => Navigator.of(context).pop(), + child: const Text('Got it!'), + ), + ], + ), + ); + } +} \ No newline at end of file