Skip to main content

Overview

CometChatMessageComposer is a Widget that enables users to write and send a variety of messages, including text, image, video, and custom messages. Features such as Live Reaction, Attachments, Message Editing, Rich Text Formatting, Code Blocks, and Inline Audio Recording are supported. CometChatMessageComposer is comprised of the following Base Widgets:
Base WidgetsDescription
MessageInputProvides a basic layout for the contents, such as the TextField and buttons
ActionSheetPresents a list of options in either a list or grid mode
In V6, the composer is powered by MessageComposerBloc and decomposed into focused sub-widgets.

Usage

Integration

1. Using Navigator to Launch CometChatMessageComposer
Navigator.push(context, MaterialPageRoute(builder: (context) => CometChatMessageComposer(user: user)));
2. Embedding CometChatMessageComposer as a Widget in the build Method
import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';
import 'package:flutter/material.dart';

class MessageComposerScreen extends StatefulWidget {
  const MessageComposerScreen({super.key});

  @override
  State<MessageComposerScreen> createState() => _MessageComposerScreenState();
}

class _MessageComposerScreenState extends State<MessageComposerScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false, // REQUIRED — composer handles keyboard internally
      body: Column(
        children: [
          Expanded(child: CometChatMessageList(user: user)),
          CometChatMessageComposer(user: user),
        ],
      ),
    );
  }
}

Actions

1. OnSendButtonClick
The OnSendButtonClick event gets activated when the send message button is clicked.
CometChatMessageComposer(
  user: user,
  onSendButtonTap: (BuildContext context, BaseMessage baseMessage, PreviewMessageMode? previewMessageMode) {
    // Handle send
  },
)

2. onChange
Handles changes in the value of text in the input field.
CometChatMessageComposer(
  user: user,
  onChange: (String? text) {
    // Handle text change
  },
)

3. onError
Listens for any errors that occur.
CometChatMessageComposer(
  user: user,
  onError: (e) {
    // Handle error
  },
)

Filters

CometChatMessageComposer widget does not have any available filters.

Events

The CometChatMessageComposer Widget does not emit any events of its own.

Customization

Style

1. CometChatMessageComposerStyle
CometChatMessageComposer(
  user: user,
  messageComposerStyle: CometChatMessageComposerStyle(
    sendButtonIconBackgroundColor: Color(0xFFF76808),
    secondaryButtonIconColor: Color(0xFFF76808),
    auxiliaryButtonIconColor: Color(0xFFF76808),
  ),
)
2. MediaRecorder Style
CometChatMessageComposer(
  user: user,
  messageComposerStyle: CometChatMessageComposerStyle(
    mediaRecorderStyle: CometChatMediaRecorderStyle(
      recordIndicatorBackgroundColor: Color(0xFFF44649),
      recordIndicatorBorderRadius: BorderRadius.circular(20),
    ),
  ),
)

Functionality

CometChatMessageComposer(
  user: user,
  placeholderText: "Type a message...",
  disableMentions: true,
)

Message Composer Properties

PropertyData TypeDescription
userUser?Sets user for the message composer.
groupGroup?Sets group for the message composer.
messageComposerStyleCometChatMessageComposerStyle?Sets style for the message composer.
placeholderTextString?Hint text for the input field.
textString?Initial text for the input field.
onChangeFunction(String text)?Callback triggered when text changes.
textEditingControllerTextEditingController?Controls the state of the text field.
maxLineint?Maximum number of lines allowed.
disableMentionsbool?Disables mentions in the composer.
disableTypingEventsboolDisables typing events.
disableSoundForMessagesboolDisables sound for sent messages.
parentMessageIdintID of the parent message (default is 0).
sendButtonViewWidget?Custom send button widget.
attachmentIconWidget?Custom attachment icon.
voiceRecordingIconWidget?Custom voice recording icon.
auxiliaryButtonViewComposerWidgetBuilder?UI component as auxiliary button.
secondaryButtonViewComposerWidgetBuilder?UI component as secondary button.
hideVoiceRecordingButtonbool?Hide the voice recording button.
attachmentOptionsComposerActionsBuilder?Provides options for file attachments.
hideAttachmentButtonbool?Hide/display attachment button.
hideImageAttachmentOptionbool?Hide/display image attachment option.
hideVideoAttachmentOptionbool?Hide/display video attachment option.
hideAudioAttachmentOptionbool?Hide/display audio attachment option.
hideFileAttachmentOptionbool?Hide/display file attachment option.
hidePollsOptionbool?Hide/display polls option.
onSendButtonTapFunction(BuildContext, BaseMessage, PreviewMessageMode?)?Callback when send button is tapped.
onErrorOnError?Callback to handle errors.
hideSendButtonbool?Hide/display the send button.
hideStickersButtonbool?Hide/display the sticker button.
sendButtonIconWidget?Custom send button icon.
richTextConfigurationRichTextConfiguration?Configuration for rich text formatting toolbar. See Rich Text section below.
richTextToolbarViewWidget Function(BuildContext, TextEditingController, RichTextFormatterManager)?Custom rich text toolbar widget.
onRichTextFormatAppliedvoid Function(RichTextFormatType)?Callback when a rich text format is applied.
hideBottomSafeAreaboolHide bottom safe area padding (default: false).

Advanced

TextFormatters

CometChatMessageComposer(
  user: user,
  textFormatters: [
    CometChatMentionsFormatter(
      style: CometChatMentionsStyle(
        mentionSelfTextBackgroundColor: Color(0xFFF76808),
        mentionTextBackgroundColor: Colors.white,
        mentionTextColor: Colors.black,
        mentionSelfTextColor: Colors.white,
      ),
    ),
  ],
)

AttachmentOptions

CometChatMessageComposer(
  user: user,
  attachmentOptions: (context, user, group, id) {
    return <CometChatMessageComposerAction>[
      CometChatMessageComposerAction(
        id: "Custom Option",
        title: "Custom Option",
        icon: Icon(Icons.add_box, color: Colors.black),
      ),
    ];
  },
)

AuxiliaryButton Widget

You can customize the auxiliary button area (mic, sticker, etc.) using the auxiliaryButtonView parameter:
CometChatMessageComposer(
  user: user,
  auxiliaryButtonView: (context, user, group, id) {
    return Row(
      children: [
        IconButton(
          icon: Icon(Icons.location_pin, color: Color(0xFF6852D6)),
          onPressed: () {
            // Handle location sharing
          },
        ),
      ],
    );
  },
)

Rich Text Formatting

The composer includes a WYSIWYG rich text toolbar. Configure it via richTextConfiguration:

Enable with defaults

CometChatMessageComposer(
  user: user,
  richTextConfiguration: RichTextConfiguration(),
)

Toolbar modes

ModeDescription
RichTextToolbarMode.alwaysVisibleToolbar always shown (default)
RichTextToolbarMode.onSelectionToolbar shown when text is selected
RichTextToolbarMode.disabledRich text formatting disabled
CometChatMessageComposer(
  user: user,
  richTextConfiguration: RichTextConfiguration(
    toolbarMode: RichTextToolbarMode.onSelection,
  ),
)

Disable specific formats

CometChatMessageComposer(
  user: user,
  richTextConfiguration: RichTextConfiguration(
    enableCodeBlock: false,
    enableBlockquote: false,
    enableOrderedList: false,
  ),
)

RichTextConfiguration properties

PropertyTypeDefaultDescription
toolbarModeRichTextToolbarModealwaysVisibleHow the toolbar is displayed
previewModeRichTextPreviewModeonFormattingHow the preview is displayed
enableAutoFormattingbooltrueAuto-detect and format Markdown as user types
enableBoldbooltrueBold (**text**)
enableItalicbooltrueItalic (_text_)
enableUnderlinebooltrueUnderline (<u>text</u>)
enableStrikethroughbooltrueStrikethrough (~~text~~)
enableInlineCodebooltrueInline code (`code`)
enableCodeBlockbooltrueCode block (```code```)
enableLinksbooltrueLinks ([text](url))
enableBulletListbooltrueBullet list (- item)
enableOrderedListbooltrueOrdered list (1. item)
enableBlockquotebooltrueBlockquote (> text)

Custom toolbar view

CometChatMessageComposer(
  user: user,
  richTextConfiguration: RichTextConfiguration(),
  richTextToolbarView: (context, controller, manager) {
    return Row(
      children: [
        IconButton(
          icon: Icon(Icons.format_bold),
          onPressed: () => manager.applyFormat(RichTextFormatType.bold),
        ),
        IconButton(
          icon: Icon(Icons.format_italic),
          onPressed: () => manager.applyFormat(RichTextFormatType.italic),
        ),
      ],
    );
  },
)

V6 Architecture

Sub-Widget Decomposition

WidgetPurpose
AttachmentOptionsOverlayAttachment picker overlay
MessageComposerAuxiliaryButtonsAuxiliary button area
MessageComposerSecondaryButtonsSecondary button area
MessageComposerSendButtonSend button
MessageComposerSuggestionListSuggestion/mention list
ComposerAttachmentUtilsAttachment utilities

BLoC Architecture

ComponentDescription
MessageComposerBlocManages composer state
MessageComposerEventEvents: SendTextMessage, SendMediaMessage, EditTextMessage, StartTyping, EndTyping, etc.
MessageComposerStateComposer state

Use Cases

Use CaseDescription
SendTextMessageUseCaseSends text messages
SendMediaMessageUseCaseSends media messages
SendCustomMessageUseCaseSends custom messages
EditMessageUseCaseEdits messages
TypingUseCasesStart/end typing indicators
GetLoggedInUserUseCaseGets the logged-in user