likeunlikefunction method

Future<void> likeunlikefunction()

Implementation

Future<void> likeunlikefunction() async {
  bool currentstatus = xcomment!.value!.didIlike;
  if (currentstatus) {
    xcomment!.value!.didIlike = false;
    xcomment!.value!.likeCount--;
  } else {
    xcomment!.value!.didIlike = true;
    xcomment!.value!.likeCount++;
  }

  if (!xcomment!.value!.didIlike) {
    PostCommentUnLikeResponse response = await service.postsServices
        .commentunlike(commentID: xcomment!.value!.commentID);

    if (!response.result.status) {
      log(response.result.description);
      if (currentstatus) {
        xcomment!.value!.likeCount--;
      } else {
        xcomment!.value!.likeCount++;
      }
      xcomment!.value!.didIlike = !xcomment!.value!.didIlike;
      return;
    }
  } else {
    PostCommentLikeResponse response = await service.postsServices
        .commentlike(commentID: xcomment!.value!.commentID);

    if (!response.result.status) {
      log(response.result.description);
      if (currentstatus) {
        xcomment!.value!.likeCount--;
      } else {
        xcomment!.value!.likeCount++;
      }
      xcomment!.value!.didIlike = !xcomment!.value!.didIlike;
      return;
    }
  }
}