Browse SDKs · Flutter
Platform
SDKsFlutter

Create a custom message

Create a structured application-defined message with the OpenIM Flutter SDK.

Copy

Encapsulate application-specific custom data structures (such as polls, red packets, or order cards) into a message object ready for delivery:

Parameters

ParameterTypeRequiredDescription
dataStringYesCore custom payload, typically formatted as a JSON string.
extensionStringYesCustom extension string, commonly used to identify schema namespaces or protocol versions.
descriptionStringYesPlain text summary of the custom message, used for offline push notifications or fallback UI rendering.

Code example

final message = await OpenIM.iMManager.messageManager.createCustomMessage(
  data: jsonEncode({'version': 1, 'orderID': orderID}),
  extension: jsonEncode({'schema': 'com.example.order'}),
  description: 'Order card',
);

Recipients should validate the payload structure and schema version upon decoding. Authoritative business state must remain on your application backend; custom messages serve as delivery carriers.

Return value

Returns a Future resolving to a custom Message object ready for transmission. Its custom data is stored in customElem.

State changes after the call

Creating a message only constructs the local message data structure in memory; it does not perform network transmission and does not trigger new-message event callbacks. Once constructed, pass the returned Message instance to Send a message to deliver it to a direct or group conversation.