Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/src/like_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -126,15 +131,19 @@ class LikeButtonState extends State<LikeButton> with TickerProviderStateMixin {
late Animation<double> _opacityAnimation;

AnimationController? get controller => _controller;

AnimationController? get likeCountController => _likeCountController;

bool? _isLiked = false;
int? _likeCount;
int? _preLikeCount;

bool? get isLiked => _isLiked;

int? get likeCount => _likeCount;

int? get preLikeCount => _preLikeCount;

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -415,9 +424,11 @@ class LikeButtonState extends State<LikeButton> 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);
Expand Down