like_button icon indicating copy to clipboard operation
like_button copied to clipboard

Animation is not shown while using onTap Feature

Open rishabhshukla7 opened this issue 4 years ago • 7 comments

I have wrapped this Like Button with my stateless Widget named Love Button The animation of this like button is working until I use onTap feature after onTap callback added to the widget the animation stops , only color is changed
Here's my Code

`class LoveButton extends StatelessWidget { @required final IconData icon; @required final IconData likedIcon; @required final Color startColor; @required final Color endColor; @required final Color dotPrimaryColor; @required final Color dotSecondaryColor; @required final Color likeColor; @required final int likeCount; @required final bool isLiked; @required final LikeButtonTapCallback onTap;

const LoveButton( {Key key, this.icon, this.dotSecondaryColor, this.dotPrimaryColor, this.endColor, this.startColor, this.likeColor, this.likedIcon, this.likeCount, this.isLiked, this.onTap}) : super(key: key); @override Widget build(BuildContext context) { return LikeButton( size: 24.0, isLiked: isLiked, circleColor: CircleColor(start: startColor, end: endColor), bubblesColor: BubblesColor( dotPrimaryColor: dotPrimaryColor, dotSecondaryColor: dotSecondaryColor, ), onTap: onTap, likeBuilder: (bool isLiked) { return !isLiked ? Icon( icon, color: Colors.grey, size: 24.0, ) : Icon( likedIcon, color: likeColor, size: 24.0, ); }, countPostion: CountPostion.left, likeCountPadding: EdgeInsets.only(right: 3), countDecoration: (Widget count, int likeCount) { var _formattedNumber = NumberFormat.compact().format( likeCount, ); if (likeCount == 0) { count = Text( "", ); } else count = Text( " ${_formattedNumber.toLowerCase()}", style: textTheme.caption.copyWith(color: colorScheme.secondary), ); return count; }, likeCount: likeCount, ); } }`

Hers My implementation of LovedButton LoveButton( onTap: (bool isLiked) async { print(isLiked); if (!isLiked) { await firestoreService.addLikes( postId: post.postId, currentUserId: sanjuUser.id, ownerId: post.ownerId); await firestoreService.addLikeToActivity( ownerId: post.ownerId, postId: post.postId, currentUserId: sanjuUser.id, mediaUrl: post.mediaUrl, timestamp: new DateTime.now().millisecondsSinceEpoch, displayType: post.type); return isLiked; } else { await firestoreService.deleteLikes( postId: post.postId, currentUserId: sanjuUser.id, ownerId: post.ownerId); await firestoreService.removeLikeFromActivity( ownerId: post.ownerId, postId: post.postId, currentUserId: sanjuUser.id); return !isLiked; } }, isLiked: _isLiked, icon: FeatherIcons.heart, likeCount: 100, likeColor: colorScheme.primary, likedIcon: Icons.favorite, endColor: colorScheme.primary, startColor: colorScheme.primaryVariant, dotPrimaryColor: colorScheme.primaryVariant, dotSecondaryColor: colorScheme.secondaryVariant, ), Please help What should I do to get that animation and background work done.

rishabhshukla7 avatar Jan 25 '21 12:01 rishabhshukla7

please provide an simple runnable demo

zmtzawqlp avatar Jan 25 '21 14:01 zmtzawqlp

This bug happens because of line 401 There should be !(_isLiked ?? true) as it is line 405

PawlikMichal25 avatar Feb 04 '21 19:02 PawlikMichal25

i think you don't get this api meaning. The input of islike is current status,and you should return actual status base on your case(maybe you will request a service, if failed, we shouldn't change the status).

zmtzawqlp avatar Feb 05 '21 01:02 zmtzawqlp

you should change status base on your case, please see detail from demo

zmtzawqlp avatar Feb 05 '21 01:02 zmtzawqlp

https://github.com/fluttercandies/like_button/blob/8ecb015abba463e34fb323f9e13f8a76eb54270b/example/lib/pages/like_button_demo.dart#L306

zmtzawqlp avatar Feb 05 '21 01:02 zmtzawqlp

I have totally same issue here. I think isLiked variable doesn't change after onTap callback function..

md2eoseo avatar Apr 23 '21 08:04 md2eoseo

In my case it worked when I return true/false instead of isLiked/!isLiked.

YDA93 avatar Mar 21 '22 19:03 YDA93

isLiked is init value

zmtzawqlp avatar Sep 29 '22 06:09 zmtzawqlp