genericUser
genericUser

Reputation: 7188

Flutter like_button animation lags on tap

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)});
  }

enter image description here

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

Answers (1)

Rehmat Singh Gill
Rehmat Singh Gill

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

Related Questions