/ 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

Receive messages in a channel

Copy link

Messages sent from other participants or members in open and group channels can be received through the onMessageReceived() method in the channel event handler, which can be used as a mixin. A BaseMessage object for each received message is one of the following three message types.

Message typeClassDescription

Text

UserMessage

A text message sent by a user

File

FileMessage

A binary file message sent by a user

Admin

AdminMessage

A text message sent by an admin through the Chat Platform API.

In cases where multiple handlers need to be registered concurrently, pass the handler's unique ID for the UNIQUE_HANDLER_ID argument in addChannelEventHandler.

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 onMessageReceived(BaseChannel channel, BaseMessage message) {
        // You can customize how to display different types of messages with the result object in the message parameter.
        if (message is UserMessage) {

        }
        else if (message is FileMessage {

        }
        else if (message is AdminMessage {

        }
    }
}

If you no longer need to listen to the event handler and receive messages, remove the channel event handler by following the implementation below.

sendbird.removeChannelEventHandler(UNIQUE_HANDLER_ID);

Receive a reply in a message thread

Copy link

Once a reply is created or deleted from a thread, the onThreadInfoUpdated() method of channel event handlers is invoked. The method returns a ThreadInfoUpdateEvent object that has the latest information about the thread. This object needs to be applied to the parent message object.

Note: Like other messages, when a reply is created in a channel, the onMessageReceived() method of the channel event handler in client apps will be called.

Class MyClass with ChannelEventHandler {
    // Add this class via sendbird.addChannelEventHandler(UNIQUE_HANDLER_ID, this).
    // Remove with sendbird.removeChannelEventHandler(UNIQUE_HANDLER_ID) when it's no longer needed.

    @override
    void onThreadInfoUpdated(BaseChannel channel, ThreadInfoUpdateEvent event) {
        // Look for a message that has event.targetMessageId and apply it to the message.
        message.applyThreadInfoUpdateEvent(event);
    }
}

List of parameters

Copy link
Parameter nameTypeDescription

channel

BaseChannel

Specifies the channel that has the message thread.

event

ThreadInfoUpdateEvent

Specifies a ThreadInfoUpdateEvent object that has the latest information about the thread.


Receive callbacks for delivery receipts

Copy link

When a message is delivered to group channel members who are online, it is automatically marked as delivered and channel members are also notified of the successful message delivery through the onDeliveryStatusUpdated() method in the channel event handler.

class CustomHandler with ChannelEventHandler{
  @override
  void onDeliveryReceiptUpdated(GroupChannel channel) {
    super.onDeliveryReceiptUpdated(channel);
  }
}

var listener = CustomHandler();
sendbirdSdk.addChannelEventHandler(identifier, listener);