Skip to content

Conversation

christianarduino
Copy link

This PR updates the LikeButton widget to support optimistic UI updates.

What changed:
• When the user taps the button, the animation starts immediately and the like/unlike state updates right away.
• An external asynchronous call (e.g., to a backend or repository) is performed to confirm the action.
• If the response is negative or an error occurs, the widget automatically reverts to the previous state, restoring the like count and animation.
• The callback mechanism was modified to enable this rollback logic.

Benefits:
• Improves app responsiveness and perceived fluidity with optimistic UI.
• Automatically handles error cases without leaving inconsistent visual states.
• Makes integration with potentially slow or failing API calls easier.

How to test
• Tap the LikeButton and verify the animation runs immediately.
• Simulate a negative response or error in the onTap/onToggleLike function to confirm rollback works.
• Check the like count updates correctly and reverts if necessary.

@zmtzawqlp
Copy link
Member

In my opinion, this is not the responsibility of LikeButton.

  1. tap button, and the animation runs immediately.
  2. send the network request, if it's failed, pop a dialog
  3. after user click dialog to close , set the old status, such like likecount/ isLiked, by setstate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants