like_button
like_button copied to clipboard
animation stopped
When i used async function inside onbutton tapped ,animation is stopped,i tried many times or it will show initial color of button not updating liked color
My code
Future<bool> onLikeButtonTapped(bool isLiked) async {
///bool val = isLiked;
print((!isLiked).toString());
if (!isLiked) {
//val = !val;
// _globalKey.currentState.onTap();
mod.addLikes(data.id);
print("liked");
} else {
//val = !val;
//_globalKey.currentState.onTap();
print("notliked");
}
/// send your request here
// final bool success= await sendRequest();
/// if failed, you can do nothing
// return success? !isLiked:isLiked;
return !isLiked;
}
LikeButton(
onTap: onLikeButtonTapped,
// key: _globalKey,
// onTap: (isLiked) {
// if (isLiked == null) {
// isLiked = true;
// mod.addLikes(data.id);
// } else {
// isLiked = true;
// print("No");
// }
// //return isLiked;
// },
size: 40,
circleColor: CircleColor(
start: Color(0xff00ddff), end: Color(0xff0099cc)),
bubblesColor: BubblesColor(
dotPrimaryColor: Color(0xff33b5e5),
dotSecondaryColor: Color(0xff0099cc),
),
likeBuilder: (bool isLiked) {
return Icon(
Icons.favorite,
color: isLiked
? Colors.deepPurpleAccent
: Colors.black,
size: 40,
);
},
likeCount:
int.parse(data.data()['likeCount'].toString()),
countBuilder: (int count, bool isLiked, String text) {
var color =
isLiked ? Colors.deepPurpleAccent : Colors.grey;
Widget result;
if (count == 0) {
result = Text(
" 0 ",
style: TextStyle(
color: color, fontWeight: FontWeight.w700),
);
} else
result = Text(
text.toString(),
style: TextStyle(
color: color, fontWeight: FontWeight.w700),
);
return result;
},
),````
please provide runnable demo
https://user-images.githubusercontent.com/59081163/119432459-fe27cb00-bd31-11eb-958d-225097208e4e.mp4
Its again getting back to initial postion
In my case I solved it by updating a variable of the Widget. That way the likeBuilder
rebuilds with that variable of the class and works. Otherwise the parameter is lost.
Tell me how can I solve it
Tell me how can I solve it
You could be more respectful and try to solve the issue with the information I provided, before giving orders to anyone. Also, I have nothing to do with this project, I'm just an internet user.
no more info for this issue, reopen if provide runnable demo