fluttercandies / like_button

Like Button is a flutter library that allows you to create a button with animation effects similar to Twitter's heart when you like something and animation effects to increase like count.
MIT License
469 stars 96 forks source link

when i scroll up and down the like count move the back state. #40

Closed kadnan0900 closed 4 years ago

kadnan0900 commented 4 years ago
  //Like Widget
  Widget _likeWidget(ChallengeModel challengeModel) {
    return LikeButton(
      onTap: (bool isLiked) async {
        feedRepository.postLikes(
            id: challengeModel.id.toString(),
            like: challengeModel.is_liked ? 0.toString() : 1.toString());
        return !isLiked;
      },
      isLiked: challengeModel.is_liked,
      likeCountPadding: const EdgeInsetsDirectional.only(start: 8),
      size: 22,
      circleColor: CircleColor(start: Colors.white, end: Colors.white),
      bubblesColor: BubblesColor(
        dotPrimaryColor: AppColors.brightSun,
        dotSecondaryColor: AppColors.brightSun,
      ),
      likeBuilder: (bool isLiked) {
        return SvgPicture.asset("assets/heart.svg",
            color: isLiked ? AppColors.brightSun : Colors.white);
      },
      likeCount: challengeModel.likes_count,
      countBuilder: (int count, bool isLiked, String text) {
        Widget result;
        if (count == 0) {
          result = Text(
            "0",
            style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
          );
        } else
          result = Text(
            text,
            style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
          );
        return result;
      },
    );
  }
zmtzawqlp commented 4 years ago

ontap(isliked){ challengeModel.is_liked=!isliked; }

https://github.com/fluttercandies/like_button/issues/24

kadnan0900 commented 4 years ago

Can you give me the proper solution of this problem ?

zmtzawqlp commented 4 years ago

onTap: (bool isLiked) async { /// save it by yourself challengeModel.likes_count =?; },

supidupicoder commented 3 years ago

Hello,

the issue here is that likeBuilder: (bool isLiked)

is called with the initially set value of isLiked.

so if it was initially false, it will always be false when being rebuild, even if it was changed in an onTap action.

any solutions to this?