Convert to using `useMemoFuture`

This commit is contained in:
krawieck 2020-09-17 18:34:03 +02:00
parent c9558a5945
commit c83d92f79d
1 changed files with 21 additions and 5 deletions

View File

@ -3,25 +3,30 @@ import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:lemmy_api_client/lemmy_api_client.dart';
import '../hooks/memo_future.dart';
import '../util/api_extensions.dart';
import '../widgets/comment_section.dart';
import '../widgets/post.dart';
import '../widgets/save_post_button.dart';
class FullPostPage extends HookWidget {
final Future<FullPostView> fullPost;
// final Future<FullPostView> fullPost;
final int id;
final String instanceUrl;
final PostView post;
FullPostPage({@required int id, @required String instanceUrl})
FullPostPage({@required this.id, @required this.instanceUrl})
: assert(id != null),
assert(instanceUrl != null),
fullPost = LemmyApi(instanceUrl).v1.getPost(id: id),
post = null;
FullPostPage.fromPostView(this.post)
: fullPost = LemmyApi(post.instanceUrl).v1.getPost(id: post.id);
: id = post.id,
instanceUrl = post.instanceUrl;
@override
Widget build(BuildContext context) {
final fullPostSnap = useFuture(this.fullPost);
final fullPostSnap =
useMemoFuture(() => LemmyApi(instanceUrl).v1.getPost(id: id));
// FALLBACK VIEW
@ -78,6 +83,17 @@ class FullPostPage extends HookWidget {
if (fullPostSnap.hasData)
CommentSection(fullPost.comments,
postCreatorId: fullPost.post.creatorId)
else if (fullPostSnap.hasError)
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 30),
child: Column(
children: [
Icon(Icons.error),
Text('Error: ${fullPostSnap.error}')
],
),
)
else
Container(
child: Center(child: CircularProgressIndicator()),