Prevent ever null being set to myVote, fixes #117

This commit is contained in:
shilangyu 2021-01-30 16:38:11 +00:00
parent 20ebcd0dfa
commit dfdaf741c3
2 changed files with 8 additions and 8 deletions

View File

@ -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)

View File

@ -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)