diff --git a/lib/pages/post_view_page.dart b/lib/pages/post_view_page.dart index 563a94b3..8a2bbcf1 100644 --- a/lib/pages/post_view_page.dart +++ b/lib/pages/post_view_page.dart @@ -754,7 +754,8 @@ class _PostViewPageState extends State { InkWell( onTap: () async { // API 요청 이전에 먼저 state를 변경한 뒤에 요청 결과에 따라 처리하기 - ArticleController(model: _article, userProvider: userProvider).setVote(true); + ArticleController(model: _article, userProvider: userProvider) + .setVote(true); _updateState(); bool res = await ArticleController( model: _article, @@ -762,7 +763,8 @@ class _PostViewPageState extends State { ).posVote(); debugPrint('좋아요 결과 ${res}'); if (!res) { - ArticleController(model: _article, userProvider: userProvider).setVote(true); + ArticleController(model: _article, userProvider: userProvider) + .setVote(true); _updateState(); } }, @@ -783,7 +785,8 @@ class _PostViewPageState extends State { InkWell( onTap: () async { // API 요청 이전에 먼저 state를 변경한 뒤에 요청 결과에 따라 처리하기 - ArticleController(model: _article, userProvider: userProvider).setVote(false); + ArticleController(model: _article, userProvider: userProvider) + .setVote(false); _updateState(); bool res = await ArticleController( model: _article, @@ -791,7 +794,8 @@ class _PostViewPageState extends State { ).negVote(); debugPrint('싫어요 결과 ${res}'); if (!res) { - ArticleController(model: _article, userProvider: userProvider).setVote(false); + ArticleController(model: _article, userProvider: userProvider) + .setVote(false); _updateState(); } }, @@ -1345,13 +1349,25 @@ class _PostViewPageState extends State { child: Row( children: [ InkWell( - onTap: () { + onTap: () async { + // API 요청 이전에 먼저 state를 변경한 뒤에 요청 결과에 따라 처리하기 CommentController( - model: curComment, + model: curComment, + userProvider: userProvider) + .setVote(true); + _updateState(); + bool res = await ArticleController( + model: _article, userProvider: userProvider, - ).posVote().then((result) { - if (result) _updateState(); - }); + ).posVote(); + debugPrint('좋아요 결과 ${res}'); + if (!res) { + CommentController( + model: curComment, + userProvider: userProvider) + .setVote(true); + _updateState(); + } }, child: _buildVoteIcons(true, curComment.my_vote, ColorsInfo.posVote, 11.52, 12.57), @@ -1370,12 +1386,24 @@ class _PostViewPageState extends State { const SizedBox(width: 12), InkWell( onTap: () async { + // API 요청 이전에 먼저 state를 변경한 뒤에 요청 결과에 따라 처리하기 CommentController( - model: curComment, + model: curComment, + userProvider: userProvider) + .setVote(false); + _updateState(); + bool res = await ArticleController( + model: _article, userProvider: userProvider, - ).negVote().then((result) { - if (result) _updateState(); - }); + ).negVote(); + debugPrint('좋아요 결과 ${res}'); + if (!res) { + CommentController( + model: curComment, + userProvider: userProvider) + .setVote(false); + _updateState(); + } }, child: _buildVoteIcons( false, diff --git a/lib/utils/post_view_utils.dart b/lib/utils/post_view_utils.dart index 36383e3d..de81b5b5 100644 --- a/lib/utils/post_view_utils.dart +++ b/lib/utils/post_view_utils.dart @@ -266,14 +266,13 @@ class CommentController { var cancelRes = await userProvider.postApiRes( "comments/$id/vote_cancel/", ); - if (cancelRes.statusCode != 200) return false; + if (cancelRes == null || cancelRes.statusCode != 200) return false; } else { var postRes = await userProvider.postApiRes( "comments/$id/vote_positive/", ); - if (postRes.statusCode != 200) return false; + if (postRes == null || postRes.statusCode != 200) return false; } - setVote(true); return true; } @@ -285,14 +284,13 @@ class CommentController { var cancelRes = await userProvider.postApiRes( "comments/$id/vote_cancel/", ); - if (cancelRes.statusCode != 200) return false; + if (cancelRes == null || cancelRes.statusCode != 200) return false; } else { var postRes = await userProvider.postApiRes( "comments/$id/vote_negative/", ); - if (postRes.statusCode != 200) return false; + if (postRes == null || postRes.statusCode != 200) return false; } - setVote(false); return true; }