Hello,
I am experiencing a problem in Flutter where adding reactions to messages in my chats results in the reaction being added locally but not persisting. Whenever I leave the view and come back, the reaction is gone. If I then try to add the same reaction again I get the error: “type ‘Null’ is not a subtype of type ‘int’ in type cast”.
I am using sendbird_sdk: ^3.2.20
I am simply calling addReaction or deleteReaction and then applying the returned event using applyReactionEvent as the docs recommend.
var currentUserId = sl().currentUser?.uid;
var existingReaction = message.reactions?.firstWhere(
(r) => r.userIds.contains(currentUserId),
orElse: () => Reaction(key: ‘’, userIds: , updatedAt: 0)
);
if (existingReaction?.key != '') {
var deleteEvent = await _channel!.deleteReaction(message, existingReaction!.key);
var deleteApplied = message.applyReactionEvent(deleteEvent);
if (!deleteApplied) print("Error: Existing reaction not removed");
}
if (existingReaction?.key == '' || existingReaction?.key != reaction.value) {
var addEvent = await _channel!.addReaction(message, reaction.value!);
var addApplied = message.applyReactionEvent(addEvent);
if (!addApplied) print("Error: New reaction not applied");
}
print('Reaction selected: ${reaction.value}');
setState(() {});
Navigator.of(context).pop();
If anyone is aware of why this is happening and how to fix it, please let me know! I would appreciate any help you could provide.