Change `fullPostFuture` to `fullPostSnap` and simplify error handling
This commit is contained in:
parent
d49715fb64
commit
e309c165d3
|
@ -29,12 +29,11 @@ class FullPostPage extends HookWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var fullPostFuture = useFuture(this.fullPost);
|
final fullPostSnap = useFuture(this.fullPost);
|
||||||
|
final fullPost = fullPostSnap.data;
|
||||||
var fullPost = fullPostFuture.data;
|
|
||||||
|
|
||||||
final savedIcon = () {
|
final savedIcon = () {
|
||||||
if (fullPost != null) {
|
if (fullPostSnap.hasData) {
|
||||||
if (fullPost.post.saved == null || !fullPost.post.saved) {
|
if (fullPost.post.saved == null || !fullPost.post.saved) {
|
||||||
return Icons.bookmark_border;
|
return Icons.bookmark_border;
|
||||||
} else {
|
} else {
|
||||||
|
@ -63,18 +62,18 @@ class FullPostPage extends HookWidget {
|
||||||
icon: Icon(Icons.more_vert), onPressed: () {}), // TODO: more menu
|
icon: Icon(Icons.more_vert), onPressed: () {}), // TODO: more menu
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: fullPost != null || post != null
|
body: fullPostSnap.hasData || post != null
|
||||||
// FUTURE SUCCESS
|
// FUTURE SUCCESS
|
||||||
? ListView(
|
? ListView(
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
children: [
|
children: [
|
||||||
if (fullPost != null)
|
if (fullPostSnap.hasData)
|
||||||
Post(fullPost.post, fullPost: true)
|
Post(fullPost.post, fullPost: true)
|
||||||
else if (post != null)
|
else if (post != null)
|
||||||
Post(post, fullPost: true)
|
Post(post, fullPost: true)
|
||||||
else
|
else
|
||||||
CircularProgressIndicator(),
|
CircularProgressIndicator(),
|
||||||
if (fullPost != null)
|
if (fullPostSnap.hasData)
|
||||||
CommentSection(fullPost.comments,
|
CommentSection(fullPost.comments,
|
||||||
postCreatorId: fullPost.post.creatorId)
|
postCreatorId: fullPost.post.creatorId)
|
||||||
else
|
else
|
||||||
|
@ -84,7 +83,7 @@ class FullPostPage extends HookWidget {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
: fullPostFuture.error != null
|
: fullPostSnap.hasError
|
||||||
// FUTURE FAILURE
|
// FUTURE FAILURE
|
||||||
? Center(
|
? Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
|
@ -92,7 +91,7 @@ class FullPostPage extends HookWidget {
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.error, size: 30),
|
Icon(Icons.error, size: 30),
|
||||||
Padding(padding: EdgeInsets.all(5)),
|
Padding(padding: EdgeInsets.all(5)),
|
||||||
Text('ERROR: ${fullPostFuture.error.toString()}'),
|
Text('ERROR: ${fullPostSnap.error.toString()}'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue