Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-flutter-uikit-v6-default.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

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(
      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.
layoutCometChatComposerLayoutComposer skeleton: singleLine (default) or doubleLine. See Layout below.
enableRichTextFormattingboolMaster switch for rich text (markdown detection, toolbar, WYSIWYG rendering). Default true.
showRichTextFormattingOptionsboolWhether the rich text toolbar UI is visible. Default true.
hideRichTextFormattingOptionsSet<FormatType>Set of format buttons to hide from the toolbar. Default {}.
richTextToolbarViewWidget Function(BuildContext, TextEditingController)?Custom rich text toolbar widget.
onRichTextFormatAppliedvoid Function(FormatType)?Callback fired when a toolbar format is applied.
hideBottomSafeAreaboolHide bottom safe area padding (default: false).
resizeToAvoidBottomInsetboolIndicates the parent Scaffold uses its default resizeToAvoidBottomInset: true and will handle keyboard insets itself. Default true. Flip to false only if you opt into the composer’s internal keyboard-aware spacing and set resizeToAvoidBottomInset: false on your Scaffold.
onKeyboardDiagnosticsCometChatKeyboardDiagnosticsCallback?Debug hook fired on every internal keyboard-state change. Leave null in production.

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
          },
        ),
      ],
    );
  },
)

Layout

The composer skeleton supports two layouts via the layout prop:
ValueDescription
CometChatComposerLayout.singleLineDefault. Text field and all buttons share a single row.
CometChatComposerLayout.doubleLineClassic v5 look — text field on its own row, buttons on a second row below a divider.
All existing props (hide flags, view slots, style, mentions, rich text, voice recording, reply/edit preview, AI options) work identically in both layouts.
CometChatMessageComposer(
  user: user,
  layout: CometChatComposerLayout.doubleLine,
)

Rich Text Formatting

The composer ships with a WYSIWYG rich-text toolbar that parses Markdown as the user types and renders formatted spans in place. Configuration is done with three flat props.

Enable with defaults

Rich text is on by default — no props required.
CometChatMessageComposer(user: user)

Show or hide the toolbar UI

showRichTextFormattingOptions controls toolbar visibility. When false, markdown is still parsed in typed text but no toolbar is rendered.
LayoutToolbar placement
singleLinePersistent row directly below the text input
doubleLineBehind an Aa toggle in the button row — tapping swaps in the toolbar
CometChatMessageComposer(
  user: user,
  showRichTextFormattingOptions: false, // parses markdown, no toolbar
)

Hide specific format buttons

Pass a Set<FormatType> listing the buttons to remove from the toolbar.
CometChatMessageComposer(
  user: user,
  hideRichTextFormattingOptions: const {
    FormatType.strikethrough,
    FormatType.codeBlock,
    FormatType.blockquote,
  },
)

Disable rich text entirely

Set enableRichTextFormatting: false to behave as a plain text field — no markdown parsing, no toolbar, regardless of the other two props.
CometChatMessageComposer(
  user: user,
  enableRichTextFormatting: false,
)

FormatType values

ValueMarkdown
FormatType.bold**text**
FormatType.italic_text_ or *text*
FormatType.underline<u>text</u>
FormatType.strikethrough~~text~~
FormatType.inlineCode`code`
FormatType.codeBlock```code```
FormatType.link[text](url)
FormatType.bulletList- item
FormatType.orderedList1. item
FormatType.blockquote> quote

Custom toolbar view

richTextToolbarView receives the active controller. Because the controller is a RichTextEditingController under the hood, apply formats directly via applyFormat.
CometChatMessageComposer(
  user: user,
  richTextToolbarView: (context, controller) {
    return Row(
      children: [
        IconButton(
          icon: const Icon(Icons.format_bold),
          onPressed: () {
            (controller as RichTextEditingController).applyFormat(FormatType.bold);
          },
        ),
        IconButton(
          icon: const Icon(Icons.format_italic),
          onPressed: () {
            (controller as RichTextEditingController).applyFormat(FormatType.italic);
          },
        ),
      ],
    );
  },
  onRichTextFormatApplied: (formatType) {
    debugPrint('Applied ${formatType.name}');
  },
)

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