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 { try {
final res = await api.run(CreateCommentLike( final res = await api.run(CreateCommentLike(
commentId: comment.comment.id, score: vote, auth: token.raw)); 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 // ignore: avoid_catches_without_on_clauses
} catch (e) { } catch (e) {
Scaffold.of(context) Scaffold.of(context)

View File

@ -390,11 +390,10 @@ class PostWidget extends HookWidget {
const Spacer(), const Spacer(),
if (!fullPost) if (!fullPost)
IconButton( IconButton(
icon: const Icon(Icons.share), icon: const Icon(Icons.share),
onPressed: () => Share.text( onPressed: () => Share.text(
'Share post url', 'Share post url', post.post.apId, 'text/plain'),
post.post.apId, ), // TODO: find a way to mark it as url
'text/plain')), // TODO: find a way to mark it as url
if (!fullPost) SavePostButton(post), if (!fullPost) SavePostButton(post),
_Voting(post), _Voting(post),
], ],
@ -440,7 +439,8 @@ class _Voting extends HookWidget {
final bool wasVoted; final bool wasVoted;
_Voting(this.post) _Voting(this.post)
: wasVoted = (post.myVote ?? VoteType.none) != VoteType.none; : assert(post != null),
wasVoted = (post.myVote ?? VoteType.none) != VoteType.none;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -456,7 +456,7 @@ class _Voting extends HookWidget {
try { try {
final res = await api.run( final res = await api.run(
CreatePostLike(postId: post.post.id, score: vote, auth: token.raw)); 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 // ignore: avoid_catches_without_on_clauses
} catch (e) { } catch (e) {
Scaffold.of(context) Scaffold.of(context)