A user can update any of their own text and file messages sent using UserMessageParams and FileMessageParams. An error is returned if a user attempts to update another user's messages. In addition, channel operators can update any messages sent in a channel.
Note: Starting from Flutter Chat SDK 3.1.0, UserMessageParams requires the message parameter.
// Update a user message.
try {
final params = UserMessageParams(message: NEW_TEXT_MESSAGE)
..customType = NEW_CUSTOM_TYPE
..data = NEW_DATA;
final message = await channel.updateUserMessage(USER_MESSAGE_ID, params);
// The message is successfully updated.
// You can check if the update operation has been performed correctly.
} catch (e) {
// Handle error.
}
// Update a file message.
try {
final params = FileMessageParams
.fromUrl(
NEW_FILE_URL,
mimeType: 'image/jpeg',
name: NEW_FILE_NAME,
size: NEW_FILE_SIZE
)
..customType = NEW_CUSTOM_TYPE;
final message = await channel.updateFileMessage(FILE_MESSAGE_ID, params);
// The message is successfully updated.
// You can check if the update operation has been performed correctly.
} catch (e) {
// Handle error.
}
If a message is updated, the onMessageUpdated() method in the channel event handler is invoked on all users' devices except the one that updated the message.
class MyClass with ChannelEventHandler {
// Add this class through sendbird.addChannelEventHandler(UNIQUE_HANDLER_ID, this).
// Or remove it through sendbird.removeChannelEventHandler(UNIQUE_HANDLER_ID) when it's no longer needed.
@override
void onMessageUpdated(BaseChannel channel, BaseMessage message) {
}
}