118 lines
3.8 KiB
Dart
118 lines
3.8 KiB
Dart
import 'package:feet/api/api.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;
|
|
const ArticlePage({super.key, required this.article});
|
|
|
|
@override
|
|
State<ArticlePage> createState() => _ArticlePageState();
|
|
}
|
|
|
|
class _ArticlePageState extends State<ArticlePage> {
|
|
void showInfoDialog(bool debugInfo) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
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'
|
|
'Is read: ${widget.article.isRead ? 'Yes' : 'No'}\n'
|
|
'Is saved: ${widget.article.isSaved ? 'Yes' : 'No'}'
|
|
: ''}',
|
|
),
|
|
actions: debugInfo
|
|
? []
|
|
: [
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
showInfoDialog(true);
|
|
},
|
|
child: const Text('Debug info')),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: InkWell(
|
|
enableFeedback: false,
|
|
onTap: () => showInfoDialog(false),
|
|
child: Text(widget.article.title),
|
|
),
|
|
actions: [
|
|
IconButton(
|
|
onPressed: () {
|
|
Share.share(widget.article.url, subject: widget.article.title);
|
|
},
|
|
icon: const Icon(Icons.share),
|
|
),
|
|
PopupMenuButton(
|
|
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!'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
},
|
|
value: 'open_in_browser',
|
|
child: const Text('Open in browser'),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
body: ListView(
|
|
children: [
|
|
Html(
|
|
data: widget.article.html,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|