Add FullPost and implement a fair bit of it

This commit is contained in:
krawieck 2020-09-02 00:05:42 +02:00
parent f5a2d3a4e1
commit 82f2084b60
2 changed files with 127 additions and 20 deletions

99
lib/pages/full_post.dart Normal file
View File

@ -0,0 +1,99 @@
import 'package:esys_flutter_share/esys_flutter_share.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:lemmy_api_client/src/models/post.dart';
import '../widgets/comment_section.dart';
import '../widgets/post.dart';
class FullPostPage extends HookWidget {
final Future<FullPost> fullPost;
final PostView post;
FullPostPage(FullPost fullPost, {this.post})
: fullPost = Future(() => fullPost);
FullPostPage.fromFuture(this.fullPost, {this.post});
void sharePost() => Share.text('Share post', post.apId, 'text/plain');
void savePost() {
//
}
@override
Widget build(BuildContext context) {
// final post
var fullPostFuture = useFuture(this.fullPost);
var fullPost = fullPostFuture.data;
final savedIcon = () {
if (fullPost != null) {
if (fullPost.post.saved == null || !fullPost.post.saved) {
return Icons.bookmark_border;
} else {
return Icons.bookmark;
}
}
if (post != null) {
if (post.saved == null || !post.saved) {
return Icons.bookmark_border;
} else {
return Icons.bookmark;
}
}
return Icons.bookmark_border;
}();
return Scaffold(
appBar: AppBar(
leading: BackButton(),
actions: [
IconButton(icon: Icon(Icons.share), onPressed: sharePost),
IconButton(icon: Icon(savedIcon), onPressed: savePost),
IconButton(
icon: Icon(Icons.more_vert), onPressed: () {}), // TODO: more menu
],
),
body: fullPost != null || post != null
// FUTURE SUCCESS
? ListView(
physics: const AlwaysScrollableScrollPhysics(),
children: [
if (fullPost != null)
Post(fullPost.post, fullPost: true)
else if (post != null)
Post(post, fullPost: true)
else
CircularProgressIndicator(),
if (fullPost != null)
CommentSection(fullPost.comments,
postCreatorId: fullPost.post.creatorId)
else
Container(
child: Center(child: CircularProgressIndicator()),
padding: EdgeInsets.only(top: 40),
),
],
)
: fullPostFuture.error != null
// FUTURE FAILURE
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.error, size: 30),
Padding(padding: EdgeInsets.all(5)),
Text('ERROR: ${fullPostFuture.error.toString()}'),
],
),
)
// FUTURE IN PROGRESS
: Container(
child: Center(child: CircularProgressIndicator()),
color: Theme.of(context).canvasColor),
);
}
}

View File

@ -6,6 +6,7 @@ import 'package:intl/intl.dart';
import 'package:lemmy_api_client/lemmy_api_client.dart';
import 'package:timeago/timeago.dart' as timeago;
import '../pages/full_post.dart';
import 'markdown_text.dart';
enum MediaType {
@ -28,11 +29,12 @@ MediaType whatType(String url) {
class Post extends StatelessWidget {
final PostView post;
final String instanceUrl;
final bool fullPost;
/// nullable
final String postUrlDomain;
Post(this.post)
Post(this.post, {this.fullPost = false})
: instanceUrl = post.communityActorId.split('/')[2],
postUrlDomain = post.url != null ? post.url.split('/')[2] : null;
@ -47,7 +49,10 @@ class Post extends StatelessWidget {
}
void _goToPost(BuildContext context) {
print('GO TO POST');
final api = LemmyApi(instanceUrl).v1;
final p = api.getPost(id: post.id);
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => FullPostPage.fromFuture(p, post: post)));
}
void _goToCommunity() {
@ -183,14 +188,15 @@ class Post extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
),
Spacer(),
Column(
children: [
IconButton(
onPressed: _showMoreMenu,
icon: Icon(Icons.more_vert),
)
],
)
if (!fullPost)
Column(
children: [
IconButton(
onPressed: _showMoreMenu,
icon: Icon(Icons.more_vert),
)
],
)
]),
),
]);
@ -314,15 +320,17 @@ class Post extends StatelessWidget {
),
),
Spacer(),
IconButton(
icon: Icon(Icons.share),
onPressed: () => Share.text('Share post url', post.apId,
'text/plain')), // TODO: find a way to mark it as url
IconButton(
icon: post.saved == true
? Icon(Icons.bookmark)
: Icon(Icons.bookmark_border),
onPressed: _savePost),
if (!fullPost)
IconButton(
icon: Icon(Icons.share),
onPressed: () => Share.text('Share post url', post.apId,
'text/plain')), // TODO: find a way to mark it as url
if (!fullPost)
IconButton(
icon: post.saved == true
? Icon(Icons.bookmark)
: Icon(Icons.bookmark_border),
onPressed: _savePost),
IconButton(
icon: Icon(Icons.arrow_upward), onPressed: _upvotePost),
Text(NumberFormat.compact().format(post.score)),
@ -339,7 +347,7 @@ class Post extends StatelessWidget {
borderRadius: BorderRadius.all(Radius.circular(20)),
),
child: InkWell(
onTap: () => _goToPost(context),
onTap: fullPost ? null : () => _goToPost(context),
child: Column(
children: [
info(),