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

Like ontap issue #56

Closed dalton5 closed 2 years ago

dalton5 commented 3 years ago

Hi,

I would like to be able in the tap event to set the liked state and change the state of the button and then call my API.

It's to avoid lag time of API call.

onTap: (statusLiked) async { // set Likebutton liked = statusLiked how to do it? return await callApi!(taped); },

How can I do it?

zmtzawqlp commented 3 years ago

return ! statusLiked;

dalton5 commented 3 years ago

if I return !statusLiked it will work however if I have an error in my API call I couldn't come back to the iniitial value. Because the return will have already been done. No?

zmtzawqlp commented 3 years ago

yes,but you can rollback status if failed

dalton5 commented 3 years ago

How?

Would you have an example?

Thanks,

renealas commented 2 years ago

Hey have the same problem, the issue is that the Animation doesn't work with the onTap. my OnTap Code is this:

onTap: (isliked) async { likeFuntion( ctx: ctx, like: isliked, //listing.isFavorite, listing: listing, ); },

And my Like funtion is:

Future<bool> likeFuntion({
    bool like,
    BuildContext ctx,
    Listing listing,
  }) async {
    if (!like) {
      Provider.of<Listings2>(ctx, listen: false).addFavorite(listing);

      if (listing.listingType != 'Web') {
        DatabaseMethods().saveNotification(
          'favorited',
          listing.userId,
          houseImage: listing.photos.first,
          listingId: listing.id,
        );
      }
    } else {
      Provider.of<Listings2>(ctx, listen: false).removeFavorite(listing.id);
    }
    listing.toggleFavoriteStatus(listing);
    return !like;
  }

It works on my Backend however the Animation is completely lost, any Ideas?

renealas commented 2 years ago

Sorry, I found how it will work, just added into the onTap of the Like button the return to the function, now the animation works again.

arindammitra06 commented 2 years ago

Sorry, I found how it will work, just added into the onTap of the Like button the return to the function, now the animation works again.

Thanks a lot. Animation works now by returning the function.