Add feedback button to popup menu

Closes #10
This commit is contained in:
Lea 2023-02-05 16:00:10 +01:00
parent e24ff355fb
commit bf6608d576
Signed by: Lea
GPG key ID: 1BAFFE8347019C42
3 changed files with 55 additions and 42 deletions

View file

@ -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<MyHomePage> {
);
},
),
PopupMenuItem(
value: "feedback",
child: const Text("Feedback"),
onTap: () async {
await openUrl(context, "https://git.amogus.cloud/Lea/feet/issues");
},
),
]),
],
),

View file

@ -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<ArticlePage> {
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<ArticlePage> {
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<ArticlePage> {
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!),

41
lib/util.dart Normal file
View file

@ -0,0 +1,41 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart';
Future<void> 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!'),
),
],
),
);
}
}