diff --git a/lib/src/like_button.dart b/lib/src/like_button.dart index 0746595..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,9 +424,11 @@ class LikeButtonState extends State with TickerProviderStateMixin { } void onTap() { - if (_controller!.isAnimating || _likeCountController!.isAnimating) { + if (widget.shouldWaitForAnimation && + (_controller!.isAnimating || _likeCountController!.isAnimating)) { return; } + if (widget.onTap != null) { widget.onTap!(_isLiked ?? true).then((bool? isLiked) { _handleIsLikeChanged(isLiked);