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 Widgets | Description |
|---|---|
| MessageInput | Provides a basic layout for the contents, such as the TextField and buttons |
| ActionSheet | Presents a list of options in either a list or grid mode |
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
| Property | Data Type | Description |
|---|---|---|
user | User? | Sets user for the message composer. |
group | Group? | Sets group for the message composer. |
messageComposerStyle | CometChatMessageComposerStyle? | Sets style for the message composer. |
placeholderText | String? | Hint text for the input field. |
text | String? | Initial text for the input field. |
onChange | Function(String text)? | Callback triggered when text changes. |
textEditingController | TextEditingController? | Controls the state of the text field. |
maxLine | int? | Maximum number of lines allowed. |
disableMentions | bool? | Disables mentions in the composer. |
disableTypingEvents | bool | Disables typing events. |
disableSoundForMessages | bool | Disables sound for sent messages. |
parentMessageId | int | ID of the parent message (default is 0). |
sendButtonView | Widget? | Custom send button widget. |
attachmentIcon | Widget? | Custom attachment icon. |
voiceRecordingIcon | Widget? | Custom voice recording icon. |
auxiliaryButtonView | ComposerWidgetBuilder? | UI component as auxiliary button. |
secondaryButtonView | ComposerWidgetBuilder? | UI component as secondary button. |
hideVoiceRecordingButton | bool? | Hide the voice recording button. |
attachmentOptions | ComposerActionsBuilder? | Provides options for file attachments. |
hideAttachmentButton | bool? | Hide/display attachment button. |
hideImageAttachmentOption | bool? | Hide/display image attachment option. |
hideVideoAttachmentOption | bool? | Hide/display video attachment option. |
hideAudioAttachmentOption | bool? | Hide/display audio attachment option. |
hideFileAttachmentOption | bool? | Hide/display file attachment option. |
hidePollsOption | bool? | Hide/display polls option. |
onSendButtonTap | Function(BuildContext, BaseMessage, PreviewMessageMode?)? | Callback when send button is tapped. |
onError | OnError? | Callback to handle errors. |
hideSendButton | bool? | Hide/display the send button. |
hideStickersButton | bool? | Hide/display the sticker button. |
sendButtonIcon | Widget? | Custom send button icon. |
richTextConfiguration | RichTextConfiguration? | Configuration for rich text formatting toolbar. See Rich Text section below. |
richTextToolbarView | Widget Function(BuildContext, TextEditingController, RichTextFormatterManager)? | Custom rich text toolbar widget. |
onRichTextFormatApplied | void Function(RichTextFormatType)? | Callback when a rich text format is applied. |
hideBottomSafeArea | bool | Hide bottom safe area padding (default: false). |
Advanced
TextFormatters
- Dart
AttachmentOptions
- Dart
AuxiliaryButton Widget
You can customize the auxiliary button area (mic, sticker, etc.) using theauxiliaryButtonView parameter:
- Dart
Rich Text Formatting
The composer includes a WYSIWYG rich text toolbar. Configure it viarichTextConfiguration:
Enable with defaults
- Dart
Toolbar modes
| Mode | Description |
|---|---|
RichTextToolbarMode.alwaysVisible | Toolbar always shown (default) |
RichTextToolbarMode.onSelection | Toolbar shown when text is selected |
RichTextToolbarMode.disabled | Rich text formatting disabled |
- Dart
Disable specific formats
- Dart
RichTextConfiguration properties
| Property | Type | Default | Description |
|---|---|---|---|
toolbarMode | RichTextToolbarMode | alwaysVisible | How the toolbar is displayed |
previewMode | RichTextPreviewMode | onFormatting | How the preview is displayed |
enableAutoFormatting | bool | true | Auto-detect and format Markdown as user types |
enableBold | bool | true | Bold (**text**) |
enableItalic | bool | true | Italic (_text_) |
enableUnderline | bool | true | Underline (<u>text</u>) |
enableStrikethrough | bool | true | Strikethrough (~~text~~) |
enableInlineCode | bool | true | Inline code (`code`) |
enableCodeBlock | bool | true | Code block (```code```) |
enableLinks | bool | true | Links ([text](url)) |
enableBulletList | bool | true | Bullet list (- item) |
enableOrderedList | bool | true | Ordered list (1. item) |
enableBlockquote | bool | true | Blockquote (> text) |
Custom toolbar view
- Dart
V6 Architecture
Sub-Widget Decomposition
| Widget | Purpose |
|---|---|
AttachmentOptionsOverlay | Attachment picker overlay |
MessageComposerAuxiliaryButtons | Auxiliary button area |
MessageComposerSecondaryButtons | Secondary button area |
MessageComposerSendButton | Send button |
MessageComposerSuggestionList | Suggestion/mention list |
ComposerAttachmentUtils | Attachment utilities |
BLoC Architecture
| Component | Description |
|---|---|
MessageComposerBloc | Manages composer state |
MessageComposerEvent | Events: SendTextMessage, SendMediaMessage, EditTextMessage, StartTyping, EndTyping, etc. |
MessageComposerState | Composer state |
Use Cases
| Use Case | Description |
|---|---|
SendTextMessageUseCase | Sends text messages |
SendMediaMessageUseCase | Sends media messages |
SendCustomMessageUseCase | Sends custom messages |
EditMessageUseCase | Edits messages |
TypingUseCases | Start/end typing indicators |
GetLoggedInUserUseCase | Gets the logged-in user |