I am triggering animation from here
void handleLikePost() {
_isLiked = widget.likes.contains(widget.currentUserId);
if (_isLiked) {
setState(() { //This is Working just fine as i remove setState
likeCount -= 1; //method.But i Want to run it with setState
method
_isLiked = false;
widget.likes.remove(widget.currentUserId);
});
animatorKey.triggerAnimation(restart: true); //working if setState is not there
} else {
setState(() {
likeCount += 1;
_isLiked = true;
widget.likes.add(widget.currentUserId);
});
}
I have initialized it with a key directly in class final AnimatorKey animatorKey = AnimatorKey();
I am using it in a gesture Detector like this GestureDetector buildPostImage() { return GestureDetector( onDoubleTap: () { handleLikePost(); //trigger of animation }, child: Stack( alignment: Alignment.center, children:[
cachedNetworkImage(
widget.mediaUrl,
),
Animator(
resetAnimationOnRebuild: true,
animatorKey: animatorKey,
duration: Duration(seconds: 1),
tween: Tween(begin: 0.5, end: 1.5),
curve: Curves.elasticInOut,
cycles: 2,
builder: (_, anim, __) => Transform.scale(
scale: anim.value,
child: Icon(
Icons.favorite,
size: 80.0,
color: Colors.red[100],
),
)),
AnimatorRebuilder(
observe: () => animatorKey,
builder: (ctx, anim, child) => Transform.scale(
scale: anim.value,
child: Icon(
Icons.favorite,
size: 80.0,
color: Colors.red[100],
),
))
],
),
);
}
I am triggering animation from here void handleLikePost() { _isLiked = widget.likes.contains(widget.currentUserId);
},
Thanx in advance for any help..