like_button icon indicating copy to clipboard operation
like_button copied to clipboard

Like ontap issue

Open dalton5 opened this issue 2 years ago • 6 comments

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?

dalton5 avatar Jul 09 '21 08:07 dalton5

return ! statusLiked;

zmtzawqlp avatar Jul 09 '21 08:07 zmtzawqlp

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?

dalton5 avatar Jul 09 '21 11:07 dalton5

yes,but you can rollback status if failed

zmtzawqlp avatar Jul 09 '21 12:07 zmtzawqlp

How?

Would you have an example?

Thanks,

dalton5 avatar Jul 09 '21 17:07 dalton5

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 avatar Feb 23 '22 20:02 renealas

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.

renealas avatar Feb 24 '22 16:02 renealas

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.

arindammitra06 avatar Aug 25 '22 17:08 arindammitra06