2020-09-02 00:05:42 +02:00
|
|
|
import 'package:esys_flutter_share/esys_flutter_share.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
2020-09-03 13:02:38 +02:00
|
|
|
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
2020-09-02 00:05:42 +02:00
|
|
|
|
2020-09-09 17:41:54 +02:00
|
|
|
import '../util/api_extensions.dart';
|
2020-09-02 00:05:42 +02:00
|
|
|
import '../widgets/comment_section.dart';
|
|
|
|
import '../widgets/post.dart';
|
|
|
|
|
|
|
|
class FullPostPage extends HookWidget {
|
2020-09-06 00:20:08 +02:00
|
|
|
final Future<FullPostView> fullPost;
|
2020-09-02 00:05:42 +02:00
|
|
|
final PostView post;
|
|
|
|
|
2020-09-03 13:02:38 +02:00
|
|
|
FullPostPage({@required int id, @required String instanceUrl})
|
|
|
|
: assert(id != null),
|
|
|
|
assert(instanceUrl != null),
|
|
|
|
fullPost = LemmyApi(instanceUrl).v1.getPost(id: id),
|
|
|
|
post = null;
|
|
|
|
FullPostPage.fromPostView(this.post)
|
2020-09-09 17:41:54 +02:00
|
|
|
: fullPost = LemmyApi(post.instanceUrl).v1.getPost(id: post.id);
|
2020-09-02 00:05:42 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-09-03 13:56:37 +02:00
|
|
|
final fullPostSnap = useFuture(this.fullPost);
|
2020-09-09 19:23:41 +02:00
|
|
|
|
|
|
|
// FALLBACK VIEW
|
|
|
|
|
|
|
|
if (!fullPostSnap.hasData && this.post == null) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(),
|
|
|
|
body: Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
if (fullPostSnap.hasError)
|
|
|
|
Text(fullPostSnap.error.toString())
|
|
|
|
else
|
|
|
|
const CircularProgressIndicator(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// VARIABLES
|
|
|
|
|
|
|
|
final post = fullPostSnap.hasData ? fullPostSnap.data.post : this.post;
|
|
|
|
|
2020-09-03 13:56:37 +02:00
|
|
|
final fullPost = fullPostSnap.data;
|
2020-09-02 00:05:42 +02:00
|
|
|
|
2020-09-09 19:23:41 +02:00
|
|
|
final savedIcon = (post.saved == null || !post.saved)
|
|
|
|
? Icons.bookmark_border
|
|
|
|
: Icons.bookmark;
|
|
|
|
|
|
|
|
// FUNCTIONS
|
2020-09-02 00:05:42 +02:00
|
|
|
|
2020-09-09 19:23:41 +02:00
|
|
|
sharePost() => Share.text('Share post', post.apId, 'text/plain');
|
2020-09-02 00:05:42 +02:00
|
|
|
|
2020-09-09 19:23:41 +02:00
|
|
|
savePost() {
|
|
|
|
print('SAVE POST');
|
|
|
|
}
|
2020-09-02 00:05:42 +02:00
|
|
|
|
|
|
|
return Scaffold(
|
2020-09-09 19:23:41 +02:00
|
|
|
appBar: AppBar(
|
|
|
|
leading: BackButton(),
|
|
|
|
actions: [
|
|
|
|
IconButton(icon: Icon(Icons.share), onPressed: sharePost),
|
|
|
|
IconButton(icon: Icon(savedIcon), onPressed: savePost),
|
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.more_vert),
|
2020-09-09 21:23:48 +02:00
|
|
|
onPressed: () => Post.showMoreMenu(context, post)),
|
2020-09-09 19:23:41 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
body: ListView(
|
|
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
|
|
children: [
|
|
|
|
Post(post, fullPost: true),
|
|
|
|
if (fullPostSnap.hasData)
|
|
|
|
CommentSection(fullPost.comments,
|
|
|
|
postCreatorId: fullPost.post.creatorId)
|
|
|
|
else
|
|
|
|
Container(
|
|
|
|
child: Center(child: CircularProgressIndicator()),
|
|
|
|
padding: EdgeInsets.only(top: 40),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
));
|
2020-09-02 00:05:42 +02:00
|
|
|
}
|
|
|
|
}
|