/ SDKs / Flutter
SDKs
Chat SDKs Flutter v4
Chat SDKs Flutter
Chat SDKs
Flutter
Version 4

Update a message

Copy link

A user can update any of their own text and file messages sent using UserMessageUpdateParams and FileMessageUpdateParams. 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.

// Update a user message.
try {
  final params = UserMessageUpdateParams(message: 'NEW_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 = FileMessageUpdateParams()
    ..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 MyOpenChannelHandler extends OpenChannelHandler {
  @override
  void onMessageUpdated(BaseChannel channel, BaseMessage message) {
  }
}