From e309c165d3d584635a524e0e6dd46869a0bb1ee8 Mon Sep 17 00:00:00 2001 From: krawieck Date: Thu, 3 Sep 2020 13:56:37 +0200 Subject: [PATCH] Change `fullPostFuture` to `fullPostSnap` and simplify error handling --- lib/pages/full_post.dart | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/pages/full_post.dart b/lib/pages/full_post.dart index a1677f0..c6bedcd 100644 --- a/lib/pages/full_post.dart +++ b/lib/pages/full_post.dart @@ -29,12 +29,11 @@ class FullPostPage extends HookWidget { @override Widget build(BuildContext context) { - var fullPostFuture = useFuture(this.fullPost); - - var fullPost = fullPostFuture.data; + final fullPostSnap = useFuture(this.fullPost); + final fullPost = fullPostSnap.data; final savedIcon = () { - if (fullPost != null) { + if (fullPostSnap.hasData) { if (fullPost.post.saved == null || !fullPost.post.saved) { return Icons.bookmark_border; } else { @@ -63,18 +62,18 @@ class FullPostPage extends HookWidget { icon: Icon(Icons.more_vert), onPressed: () {}), // TODO: more menu ], ), - body: fullPost != null || post != null + body: fullPostSnap.hasData || post != null // FUTURE SUCCESS ? ListView( physics: const AlwaysScrollableScrollPhysics(), children: [ - if (fullPost != null) + if (fullPostSnap.hasData) Post(fullPost.post, fullPost: true) else if (post != null) Post(post, fullPost: true) else CircularProgressIndicator(), - if (fullPost != null) + if (fullPostSnap.hasData) CommentSection(fullPost.comments, postCreatorId: fullPost.post.creatorId) else @@ -84,7 +83,7 @@ class FullPostPage extends HookWidget { ), ], ) - : fullPostFuture.error != null + : fullPostSnap.hasError // FUTURE FAILURE ? Center( child: Column( @@ -92,7 +91,7 @@ class FullPostPage extends HookWidget { children: [ Icon(Icons.error, size: 30), Padding(padding: EdgeInsets.all(5)), - Text('ERROR: ${fullPostFuture.error.toString()}'), + Text('ERROR: ${fullPostSnap.error.toString()}'), ], ), )