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

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. 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 addChannelHandler().

class MyOpenChannelHandler extends OpenChannelHandler {
  // Add this object through SendbirdChat.addChannelHandler('UNIQUE_HANDLER_ID', this).
  // Or remove it through SendbirdChat.removeChannelHandler('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) {
      // ...
    }
  }
}

class MyGroupChannelHandler extends GroupChannelHandler {
  // ...
}

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

SendbirdChat.removeChannelHandler('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 MyOpenChannelHandler extends OpenChannelHandler {
  @override
  void onThreadInfoUpdated(BaseChannel channel, ThreadInfoUpdateEvent event) {
    // Look for a message that has event.targetMessageId and apply it to the message.
    message.applyThreadInfoUpdateEvent(event);
  }
}

class MyGroupChannelHandler extends GroupChannelHandler {
  // ...
}

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 MyGroupChannelHandler extends GroupChannelHandler {
  @override
  void onDeliveryStatusUpdated(GroupChannel channel) {
  }
}