/ SDKs / Flutter
SDKs
Chat SDKs Flutter v3
Chat SDKs Flutter
Chat SDKs
Flutter
Version 3
Sendbird Chat SDK v3 for Flutter is no longer supported as a new version is released. Check out our latest Chat SDK v4

Delete a message

Copy link

Users can delete any message they themselves have sent. An error is returned if a user attempts to delete messages sent by other users. Also channel operators can delete any messages in a channel.

try {
    await channel.deleteMessage(messageID);
    // The messageID parameter indicates a messageID from the BaseMessage object.
    // The message is successfully deleted from the channel.
} catch (e) {
    // Handle error.
}

After a message is successfully deleted, the onMessageDeleted() method in the channel event handler is invoked on all users' devices including the device where the message was deleted.

class MyClass with ChannelEventHandler {
    // Add this class through sdk.addChannelEventHandler(UNIQUE_HANDLER_ID, this).
    // Or remove it through sdk.removeChannelEventHandler(UNIQUE_HANDLER_ID) when it is no longer needed.

    @override
    void onMessageDeleted(BaseChannel channel, int messageId) {

    }
}