From 6be3d06022cbd17afccb0189fa10966e884cd43a Mon Sep 17 00:00:00 2001 From: zubairehman Date: Thu, 7 Mar 2024 10:17:19 +0100 Subject: [PATCH 1/2] - removed wanting to complete the animation if user pressed the button multiple times --- lib/src/like_button.dart | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/src/like_button.dart b/lib/src/like_button.dart index 0746595..434408c 100644 --- a/lib/src/like_button.dart +++ b/lib/src/like_button.dart @@ -415,9 +415,6 @@ class LikeButtonState extends State with TickerProviderStateMixin { } void onTap() { - if (_controller!.isAnimating || _likeCountController!.isAnimating) { - return; - } if (widget.onTap != null) { widget.onTap!(_isLiked ?? true).then((bool? isLiked) { _handleIsLikeChanged(isLiked); From 885847ae93d1c32f67859a4538a51ee020733861 Mon Sep 17 00:00:00 2001 From: zubairehman Date: Fri, 8 Mar 2024 07:20:14 +0100 Subject: [PATCH 2/2] - added a logic that let's user to wait for an animation before resetting the controller --- lib/src/like_button.dart | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/src/like_button.dart b/lib/src/like_button.dart index 434408c..b7e6747 100644 --- a/lib/src/like_button.dart +++ b/lib/src/like_button.dart @@ -18,6 +18,7 @@ class LikeButton extends StatefulWidget { double? circleSize, this.likeCount, this.isLiked = false, + this.shouldWaitForAnimation = true, this.mainAxisAlignment = MainAxisAlignment.center, this.crossAxisAlignment = CrossAxisAlignment.center, this.animationDuration = const Duration(milliseconds: 1000), @@ -67,6 +68,10 @@ class LikeButton extends StatefulWidget { /// you can get current value from onTap/countBuilder final bool? isLiked; + /// whether it should wait for the animation to finish before starting a new + /// animation + final bool shouldWaitForAnimation; + /// like count /// if null, will not show /// it's initial value @@ -126,6 +131,7 @@ class LikeButtonState extends State with TickerProviderStateMixin { late Animation _opacityAnimation; AnimationController? get controller => _controller; + AnimationController? get likeCountController => _likeCountController; bool? _isLiked = false; @@ -133,8 +139,11 @@ class LikeButtonState extends State with TickerProviderStateMixin { int? _preLikeCount; bool? get isLiked => _isLiked; + int? get likeCount => _likeCount; + int? get preLikeCount => _preLikeCount; + @override void initState() { super.initState(); @@ -415,6 +424,11 @@ class LikeButtonState extends State with TickerProviderStateMixin { } void onTap() { + if (widget.shouldWaitForAnimation && + (_controller!.isAnimating || _likeCountController!.isAnimating)) { + return; + } + if (widget.onTap != null) { widget.onTap!(_isLiked ?? true).then((bool? isLiked) { _handleIsLikeChanged(isLiked);