From dfdaf741c3b1d48e66b45c134a740d32008d11ff Mon Sep 17 00:00:00 2001 From: shilangyu Date: Sat, 30 Jan 2021 16:38:11 +0000 Subject: [PATCH] Prevent ever null being set to myVote, fixes #117 --- lib/widgets/comment.dart | 2 +- lib/widgets/post.dart | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/widgets/comment.dart b/lib/widgets/comment.dart index e8e06d8..2a311ee 100644 --- a/lib/widgets/comment.dart +++ b/lib/widgets/comment.dart @@ -205,7 +205,7 @@ class CommentWidget extends HookWidget { try { final res = await api.run(CreateCommentLike( commentId: comment.comment.id, score: vote, auth: token.raw)); - myVote.value = res.commentView.myVote; + myVote.value = res.commentView.myVote ?? VoteType.none; // ignore: avoid_catches_without_on_clauses } catch (e) { Scaffold.of(context) diff --git a/lib/widgets/post.dart b/lib/widgets/post.dart index 0fd7f11..acceac6 100644 --- a/lib/widgets/post.dart +++ b/lib/widgets/post.dart @@ -390,11 +390,10 @@ class PostWidget extends HookWidget { const Spacer(), if (!fullPost) IconButton( - icon: const Icon(Icons.share), - onPressed: () => Share.text( - 'Share post url', - post.post.apId, - 'text/plain')), // TODO: find a way to mark it as url + icon: const Icon(Icons.share), + onPressed: () => Share.text( + 'Share post url', post.post.apId, 'text/plain'), + ), // TODO: find a way to mark it as url if (!fullPost) SavePostButton(post), _Voting(post), ], @@ -440,7 +439,8 @@ class _Voting extends HookWidget { final bool wasVoted; _Voting(this.post) - : wasVoted = (post.myVote ?? VoteType.none) != VoteType.none; + : assert(post != null), + wasVoted = (post.myVote ?? VoteType.none) != VoteType.none; @override Widget build(BuildContext context) { @@ -456,7 +456,7 @@ class _Voting extends HookWidget { try { final res = await api.run( CreatePostLike(postId: post.post.id, score: vote, auth: token.raw)); - myVote.value = res.myVote; + myVote.value = res.myVote ?? VoteType.none; // ignore: avoid_catches_without_on_clauses } catch (e) { Scaffold.of(context)