Reputation: 7188
I'm using https://pub.dev/packages/like_button version like_button: ^1.0.4.
LikeButton(
onTap: (value) {
onGroupVotePress(document);
return Future.value(!value);
},
),
When I'm running my onGroupVotePress
function my like_button animation crashes.
void onGroupVotePress(DocumentSnapshot document) {
Network().appendToGroupList(document.id);
Network().appendToGroupList(document.id);
}
My appendToGroupList
function is a simple firestore update:
Future appendToGroupList(String groupId, String field, List list) async {
FirebaseFirestore.instance
.collection('groups')
.doc(groupId)
.update({field: FieldValue.arrayUnion(list)});
}
Why adding a simple void function to onTap case the like_button to lag?
Also how can I run code after the like_button onTap finished?
Thanks.
Upvotes: 0
Views: 327
Reputation: 619
Try the below code:
LikeButton(
onTap: (value) async {
await onGroupVotePress(document);
return !value;
},
),
Future<void> onGroupVotePress(DocumentSnapshot document) async {
await Network().appendToGroupList(document.id);
await Network().appendToGroupList(document.id);
}
Future<void> appendToGroupList(String groupId, String field, List list) async {
await FirebaseFirestore.instance.collection('groups').doc(groupId).update({
field: FieldValue.arrayUnion(list)
});
}
Upvotes: 1