AI Integration Quick Reference
AI Integration Quick Reference
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:
In V6, the composer is powered by
MessageComposerBloc and decomposed into focused sub-widgets.
Usage
Integration
1. Using Navigator to Launch CometChatMessageComposer
- Dart
2. Embedding CometChatMessageComposer as a Widget in the build Method
- Dart
Actions
1. OnSendButtonClick
TheOnSendButtonClick event gets activated when the send message button is clicked.
- Dart
2. onChange
Handles changes in the value of text in the input field.- Dart
3. onError
Listens for any errors that occur.- Dart
Filters
CometChatMessageComposer widget does not have any available filters.
Events
TheCometChatMessageComposer Widget does not emit any events of its own.
Customization
Style
1. CometChatMessageComposerStyle
- Dart
2. MediaRecorder Style
- Dart
Functionality
- Dart
Message Composer Properties
Advanced
TextFormatters
- Dart
AttachmentOptions
- Dart
AuxiliaryButton Widget
You can customize the auxiliary button area (mic, sticker, etc.) using theauxiliaryButtonView parameter:
- Dart
Layout
The composer skeleton supports two layouts via thelayout prop:
All existing props (hide flags, view slots, style, mentions, rich text, voice recording, reply/edit preview, AI options) work identically in both layouts.
- Dart
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.- Dart
Show or hide the toolbar UI
showRichTextFormattingOptions controls toolbar visibility. When false, markdown is still parsed in typed text but no toolbar is rendered.
- Dart
Hide specific format buttons
Pass aSet<FormatType> listing the buttons to remove from the toolbar.
- Dart
Disable rich text entirely
SetenableRichTextFormatting: false to behave as a plain text field — no markdown parsing, no toolbar, regardless of the other two props.
- Dart
FormatType values
Custom toolbar view
richTextToolbarView receives the active controller. Because the controller is a RichTextEditingController under the hood, apply formats directly via applyFormat.
- Dart
Trailing toolbar actions
Available since v6.1.1richTextToolbarActions appends your own buttons at the trailing end of the built-in toolbar — after the format buttons, separated by a divider — without replacing the toolbar the way richTextToolbarView does. It takes the same ComposerActionsBuilder shape as attachmentOptions and returns a list of CometChatMessageComposerAction items. Each action renders as an icon button, with its title as the tooltip.
For toolbar actions, set the action’s onToolbarTap callback. It receives the BuildContext and the composer’s active TextEditingController, so the action can read the current text and selection and mutate the draft — the composer stays the owner of the field. The toolbar calls only onToolbarTap; an action’s onItemClick and style are not used here.
- Dart
richTextToolbarView replaces it, and not while a code segment has focus.
On web, tapping a toolbar button can blur the text field and collapse the selection before your handler runs. Fall back to the controller’s
lastNonCollapsedSelection — the most recent selection that spanned at least one character — and bounds-check it against the current text.applyInlineStyle(start, end, style, id: ...) and removeInlineStyle(start, end, id: ...). Styles applied under the same id replace each other, different IDs compose with the built-in formats, and the styling is local to the composer — it is not sent with the message.
Leaving mentions alone
A toolbar action that restyles a range will happily run over a mention, which should keep the styling the mentions formatter gives it.RichTextEditingController.getMentionRanges() returns the mention ranges currently tracked in the text, sorted by start offset, so an action can skip them.
The ranges come from the attached CometChatMentionsFormatter — the same source the field styles mentions from — so they stay in step with the text as it is edited. The list is empty when no mentions formatter is attached. Toolbar actions only ever receive a RichTextEditingController, so the type check below is a safeguard for code you share with other TextEditingControllers.
- Dart
Multiple Attachments
The composer can stage several media/file attachments and send them as one message.- Pick — the image/video option opens a multi-select picker, capped to the slots left on the message. Audio and documents are multi-select too.
- Stage — each pick lands in the attachment tray as a tile with a live progress ring, and starts uploading immediately.
- Send — the send button stays disabled until every tile finishes. Text typed alongside rides along as the caption, with rich-text formatting preserved as Markdown.
batchId, so the Message List groups them as one block.
Voice notes are never staged — a recording is always its own message and sends immediately. While the tray holds any tile, the mic button is hidden.
Limits and Validation
Limits come from your app’s settings in the CometChat dashboard and are read at runtime — the UI Kit does not hardcode them.
Error tiles come in two flavours and behave differently:
- Failed (network dropped) — tap the tile to retry it in place.
- Rejected (too large, wrong type, over the count) — not retryable; tapping explains why, and you remove the tile.
Disabling Multiple Attachments
Multiple attachments are on by default. Turn them off to restore the classic one-file-per-message behaviour.- Dart
Styling the Attachment Tray
The staging tray’s tiles are styled through the composer’s own style object.- Dart
Style the error alerts
- Dart
Multiple Attachments Properties
For the upload API underneath the tray, see Upload Files & Send Attachments.