Flutter: myReactions of a post not updated until reload

After adding a reaction to a post :

  1. The AmityReactionMap post.reactions reflects the change immediately.
  2. However, the List post.myReactions is not updated until a reload.

Are we doing something wrong? Is it a bug? How to update “myReactions”?

child: ListView.builder(
              controller: scrollController,
              itemCount: amityPosts.length,
              itemBuilder: (context, index) {
                amityPosts[index].react().addReaction("test");
                print(amityPosts[index].reactions);
                print(amityPosts[index].myReactions);

Output

flutter: AmityReactionMap(reactions: {test: 1}) // reactions is updated 
flutter: [] // no update in myReactions

Desired output

flutter: AmityReactionMap(reactions: {test: 1})
flutter: [test]

Hello, could you please try this sample code:

post.react().addReaction('like').then((value) => {
       print(amityPosts[index].reactions);
      Future.delayed(Duration(milliseconds: 300), () {
            print(amityPosts[index].myReactions);
       });
});

We tried your sample code. It makes no difference. Even with a 5 seconds delay.

It is similar with comments: Adding a comment via
amityPosts[index].comment().create().text("text1").send()
updates latestCommentsIds but not latestComments and commentCount of a post.

In the screenshot you see 2 latestCommentsIds but only 1 latestComments and commentCount is also 1.

@devdieter We have raised a ticket to our engineer to check on this, I will keep you posted on the progress :pray:

1 Like

Hello, our team has released the enhancement to handle this issue in Flutter sdk ver 0.12.0, please let us know if you have further questions. Thank you :pray:

Hi, we updated to SDK 0.12.0. Unfortunately, we cannot notice any change in the behavior described earlier? MyReactions and latestComments still do not update immediately.

Hello @devdieter ,

you can use stream builder to listen to the updated in Amity Post object. so when ever there is any update, you will get an event with latest amity post object with update my reaction and latest comments.

StreamBuilder<AmityPost>(
      stream: amityPost.listen.stream,
      initialData: amityPost,
      builder: (context, snapshot) {
        /// Snapshot will always updated object
        final value = snapshot.data;
      },
    )

Another Approach we added in SDK 0.12.0, in case you dont want to use Streambuilder or have nested widgets, future return from the addReaction will always have latest Amity Post Object with my reaction and reactions.

amityPost.react().removeReaction('like').then((value) {
                    print(value.myReactions);
                  });
1 Like

Great, thanks for the explanation!