GeekAbdelouahed / flutter-reaction-button

Flutter Reaction Button is a customizable Flutter package that allows you to easily create interactive buttons with reaction emojis, similar to Facebook's iconic reaction buttons.
https://pub.dev/packages/flutter_reaction_button
MIT License
215 stars 78 forks source link

[Question] How to update selected reaction programmatically #9

Closed petchgabriel closed 4 years ago

petchgabriel commented 4 years ago

Assume I have 2 pages (Page A and B)

Page A have list of posts that contain a single FlutterReactionButtonCheck. Page B have a single FlutterReactionButtonCheck

My scenario is when I go to Page B and update reaction from index 1 to 2. When I come back to Page A. I wanted update a FlutterReactionButtonCheck reaction.

What I have done is send callback function from Page A to Page B. Whenever the reaction changed i will call a callbackfunction to setState of a reaction in PageA. But it still not update.

This is a call back function in Page A

updateReaction(int newReaction) {
    print('update new reaction to: $newReaction');
    setState(() {
      this.userReaction = newReaction;
    });
}

This is a FlutterReactionButtonCheck setup in Page A.

FlutterReactionButtonCheck(
              onReactionChanged: (reaction, isChecked) async {
             ....
  },
  reactions: this.reactions,
  isChecked: this.userReaction == null ? false : true,
  initialReaction: GurubookReaction.defaultInitialReaction,
  selectedReaction: this.userReaction != null
  ? this.reactions[this.userReaction - 1]
  : this.reactions[0],
),

In page B whenever onReactionChanged called will trigger updateReaction(reactions.id)

Thanks in advance.

GeekAbdelouahed commented 4 years ago

@petchgabriel check the last version please 1.0.3

petchgabriel commented 4 years ago

@petchgabriel check the last version please 1.0.3

Thank you so much @GeekAbdelouahed . You save my days!!