Skip to main content
{
  "component": "CometChatMessageComposer",
  "package": "cometchat_chat_uikit",
  "import": "import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';",
  "description": "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, and Message Editing are also supported.",
  "primaryOutput": {
    "prop": "onSendButtonTap",
    "type": "Function(BuildContext, BaseMessage, PreviewMessageMode?)?"
  },
  "props": {
    "data": {
      "user": {
        "type": "User?",
        "default": "null",
        "note": "User object for the message composer (one of user or group is required)"
      },
      "group": {
        "type": "Group?",
        "default": "null",
        "note": "Group object for the message composer (one of user or group is required)"
      },
      "text": {
        "type": "String?",
        "default": "null",
        "note": "Initial text for the input field"
      },
      "parentMessageId": {
        "type": "int",
        "default": "0",
        "note": "ID of the parent message for threaded replies"
      }
    },
    "callbacks": {
      "onChange": "Function(String)?",
      "onSendButtonTap": "Function(BuildContext, BaseMessage, PreviewMessageMode?)?",
      "onError": "OnError?"
    },
    "visibility": {
      "hideVoiceRecordingButton": { "type": "bool?", "default": null },
      "hideSendButton": { "type": "bool?", "default": null },
      "hideAttachmentButton": { "type": "bool?", "default": null },
      "hideStickersButton": { "type": "bool?", "default": null },
      "disableMentions": { "type": "bool?", "default": null },
      "disableTypingEvents": { "type": "bool", "default": false }
    },
    "sound": {
      "disableSoundForMessages": { "type": "bool", "default": false },
      "customSoundForMessage": { "type": "String?", "default": null }
    },
    "viewSlots": {
      "auxiliaryButtonView": "ComposerWidgetBuilder?",
      "secondaryButtonView": "ComposerWidgetBuilder?",
      "sendButtonView": "Widget?",
      "headerView": "ComposerWidgetBuilder?",
      "footerView": "ComposerWidgetBuilder?"
    },
    "formatting": {
      "placeholderText": { "type": "String?", "default": null },
      "maxLine": { "type": "int?", "default": null },
      "padding": { "type": "EdgeInsetsGeometry?", "default": null }
    }
  },
  "events": [],
  "sdkListeners": [],
  "compositionExample": {
    "description": "CometChatMessageComposer is typically used at the bottom of a messaging screen, paired with CometChatMessageHeader and CometChatMessageList",
    "components": ["CometChatMessageHeader", "CometChatMessageList", "CometChatMessages"],
    "flow": "User types message → Composer sends message → MessageList updates"
  },
  "types": {
    "CometChatMessageComposerStyle": {
      "backgroundColor": "Color?",
      "border": "BoxBorder?",
      "borderRadius": "BorderRadiusGeometry?",
      "sendButtonIconColor": "Color?",
      "sendButtonIconBackgroundColor": "Color?",
      "textStyle": "TextStyle?",
      "placeHolderTextStyle": "TextStyle?"
    }
  }
}

Where It Fits

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, and Message Editing are also supported by it.
CometChatMessageComposer is comprised of the following Base Widgets:
Base WidgetsDescription
MessageInputThis provides a basic layout for the contents of this component, such as the TextField and buttons
ActionSheetThe ActionSheet widget presents a list of options in either a list or grid mode
import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';

// CometChatMessageComposer is typically used at the bottom of a messaging screen
class MessagingScreen extends StatelessWidget {
  final User user;
  
  const MessagingScreen({required this.user});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          CometChatMessageHeader(user: user),
          Expanded(child: CometChatMessageList(user: user)),
          CometChatMessageComposer(user: user),
        ],
      ),
    );
  }
}

Minimal Render

The simplest way to render CometChatMessageComposer:
import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';

// For a user conversation
CometChatMessageComposer(
  user: user,
)

// For a group conversation
CometChatMessageComposer(
  group: group,
)

Actions and Events

Callback Props

Component-level callbacks that fire on specific user interactions:
CallbackSignatureFires When
onSendButtonTapFunction(BuildContext, BaseMessage, PreviewMessageMode?)?User taps the send button
onChangeFunction(String)?Text in the input field changes
onErrorOnError?An error occurs
stateCallBackFunction(CometChatMessageComposerController)?Controller state callback for accessing controller functions
CometChatMessageComposer(
  user: user,
  onSendButtonTap: (BuildContext context, BaseMessage baseMessage, PreviewMessageMode? previewMessageMode) {
    // Handle send button tap
  },
  onChange: (String? text) {
    // Handle text change
  },
  onError: (e) {
    // Handle error
  },
)

Custom View Slots

Customize the appearance of CometChatMessageComposer by replacing default views with your own widgets.
SlotSignatureReplaces
auxiliaryButtonViewComposerWidgetBuilder?Auxiliary button area (AI, stickers)
secondaryButtonViewComposerWidgetBuilder?Secondary button area (attachment, voice)
sendButtonViewWidget?Send button
headerViewComposerWidgetBuilder?Header section above input
footerViewComposerWidgetBuilder?Footer section below input
attachmentOptionsComposerActionsBuilder?Attachment options list

Example: Custom Auxiliary Button View

CometChatMessageComposer(
  user: user,
  auxiliaryButtonView: (context, user, group, id) {
    final existingAuxiliaryOptions = CometChatUIKit.getDataSource()
        .getAuxiliaryOptions(user, group, context, id, Color(0xFFA1A1A1));
    return Row(
      children: [
        existingAuxiliaryOptions,
        Icon(
          Icons.location_pin,
          color: Color(0xFF6852D6),
        ),
      ],
    );
  },
)

Example: Custom Secondary Button View

CometChatMessageComposer(
  user: user,
  secondaryButtonView: (context, user, group, id) {
    return Icon(
      Icons.attach_file,
      color: Color(0xFF6852D6),
    );
  },
)

Example: Custom Send Button View

CometChatMessageComposer(
  user: user,
  sendButtonView: IconButton(
    onPressed: () {},
    padding: EdgeInsets.all(4),
    style: IconButton.styleFrom(
      alignment: Alignment.center,
      backgroundColor: Color(0xFFEDEAFA),
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(4),
      ),
    ),
    icon: Transform.rotate(
      angle: 150,
      child: Icon(
        Icons.send,
        size: 20,
        color: Color(0xFF6852D6),
      ),
    ),
  ),
)

Example: Custom Header View

CometChatMessageComposer(
  user: user,
  headerView: (context, user, group, id) {
    return Container(
      margin: EdgeInsets.only(bottom: 2, left: 8, right: 8),
      padding: EdgeInsets.all(8),
      decoration: BoxDecoration(
        color: Color(0xFFEDEAFA),
        borderRadius: BorderRadius.circular(8),
      ),
      child: Row(
        children: [
          Icon(Icons.volume_off, size: 20, color: Color(0xFF6852D6)),
          Text(
            "User has paused their notifications",
            style: TextStyle(fontSize: 14, fontWeight: FontWeight.w400),
          ),
        ],
      ),
    );
  },
)
CometChatMessageComposer(
  user: user,
  footerView: (context, user, group, id) {
    return Container(
      width: MediaQuery.of(context).size.width / 1.08,
      color: Colors.yellow,
      padding: const EdgeInsets.all(8),
      child: const Center(child: Text("Your Footer Widget")),
    );
  },
)
Image

Example: Custom Attachment Options

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

Styling

Customize the appearance of CometChatMessageComposer using CometChatMessageComposerStyle.

Style Properties

PropertyTypeDescription
backgroundColorColor?Background color of the message composer
borderBoxBorder?Border of the message composer
borderRadiusBorderRadiusGeometry?Border radius of the message composer
closeIconTintColor?Color for the close icon
dividerColorColor?Color of the divider
dividerHeightdouble?Height of the divider
sendButtonIconColorColor?Color of the send button icon
sendButtonIconBackgroundColorColor?Background color of the send button
sendButtonBorderRadiusBorderRadiusGeometry?Border radius of the send button
secondaryButtonIconColorColor?Color of the secondary button icon
secondaryButtonIconBackgroundColorColor?Background color of the secondary button
secondaryButtonBorderRadiusBorderRadiusGeometry?Border radius of the secondary button
auxiliaryButtonIconColorColor?Color of the auxiliary button icon
auxiliaryButtonIconBackgroundColorColor?Background color of the auxiliary button
auxiliaryButtonBorderRadiusBorderRadiusGeometry?Border radius of the auxiliary button
textStyleTextStyle?Style of the text
textColorColor?Color of the text
placeHolderTextStyleTextStyle?Style of the placeholder text
placeHolderTextColorColor?Color of the placeholder text
filledColorColor?Background color of the text input
mentionsStyleCometChatMentionsStyle?Style for mentions
mediaRecorderStyleCometChatMediaRecorderStyle?Style for media recorder
aiOptionStyleAIOptionsStyle?Style for AI options
aiOptionSheetStyleCometChatAiOptionSheetStyle?Style for AI option sheet
attachmentOptionSheetStyleCometChatAttachmentOptionSheetStyle?Style for attachment option sheet
suggestionListStyleCometChatSuggestionListStyle?Style for suggestion list
messagePreviewStyleCometChatMessagePreviewStyle?Style for message preview

Example: Custom Styling

CometChatMessageComposer(
  user: user,
  messageComposerStyle: CometChatMessageComposerStyle(
    sendButtonIconBackgroundColor: Color(0xFFF76808),
    secondaryButtonIconColor: Color(0xFFF76808),
    auxiliaryButtonIconColor: Color(0xFFF76808),
  ),
)

Example: Custom Media Recorder Style

CometChatMessageComposer(
  user: user,
  messageComposerStyle: CometChatMessageComposerStyle(
    mediaRecorderStyle: CometChatMediaRecorderStyle(
      recordIndicatorBackgroundColor: Color(0xFFF44649),
      recordIndicatorBorderRadius: BorderRadius.circular(20),
      pauseButtonBorderRadius: BorderRadius.circular(8),
      deleteButtonBorderRadius: BorderRadius.circular(8),
      stopButtonBorderRadius: BorderRadius.circular(8),
    ),
  ),
)

Example: Custom AI Options Style

CometChatMessageComposer(
  user: user,
  messageComposerStyle: CometChatMessageComposerStyle(
    aiOptionStyle: AIOptionsStyle(
      backgroundColor: Color(0xFFE4EBF5),
      border: Border.all(width: 3, color: Colors.red),
    ),
  ),
)

Advanced

Text Formatters

Assigns the list of text formatters. To configure the existing Mentions look and feel check out CometChatMentionsFormatter.
CometChatMessageComposer(
  user: user,
  textFormatters: [
    CometChatMentionsFormatter(
      style: CometChatMentionsStyle(
        mentionSelfTextBackgroundColor: Color(0xFFF76808),
        mentionTextBackgroundColor: Colors.white,
        mentionTextColor: Colors.black,
        mentionSelfTextColor: Colors.white,
      ),
    ),
  ],
)

Props Reference

PropTypeDefaultDescription
userUser?nullUser object for the message composer
groupGroup?nullGroup object 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)?-Callback triggered when text changes
textEditingControllerTextEditingController?-Controls the state of the text field
maxLineint?-Maximum number of lines allowed
disableMentionsbool?nullDisables mentions in the composer
disableTypingEventsboolfalseDisables typing events
disableSoundForMessagesboolfalseDisables sound for sent messages
customSoundForMessageString?-URL for custom sound
customSoundForMessagePackageString?-Package name for custom sound asset
parentMessageIdint0ID of the parent message
paddingEdgeInsetsGeometry?-Sets padding for the message composer
messageInputPaddingEdgeInsetsGeometry?-Sets padding for the message input field
sendButtonViewWidget?-Custom send button widget
attachmentIconWidget?-Custom attachment icon
attachmentIconURLString?-Path of the icon to show in the attachments button
voiceRecordingIconWidget?-Custom voice recording icon
aiIconWidget?-Custom AI button icon
aiIconURLString?-Path of the icon to show in the AI button
aiIconPackageNameString?-Package name for AI icon asset
auxiliaryButtonViewComposerWidgetBuilder?-UI component for auxiliary button
secondaryButtonViewComposerWidgetBuilder?-UI component for secondary button
auxiliaryButtonsAlignmentAuxiliaryButtonsAlignment?-Controls position of auxiliary button view
hideVoiceRecordingButtonbool?nullHide/display voice recording button
attachmentOptionsComposerActionsBuilder?-Provides options for file attachments
hideAttachmentButtonbool?nullHide/display attachment button
hideImageAttachmentOptionbool?nullHide/display image attachment option
hideVideoAttachmentOptionbool?nullHide/display video attachment option
hideAudioAttachmentOptionbool?nullHide/display audio attachment option
hideFileAttachmentOptionbool?nullHide/display file attachment option
hidePollsOptionbool?nullHide/display polls option
hideCollaborativeDocumentOptionbool?nullHide/display collaborative document option
hideCollaborativeWhiteboardOptionbool?nullHide/display collaborative whiteboard option
hideTakePhotoOptionbool?nullHide/display take photo option
onSendButtonTapFunction(...)?-Callback when send button is tapped
onErrorOnError?-Callback to handle errors
hideSendButtonbool?nullHide/display the send button
hideStickersButtonbool?nullHide/display the sticker button
sendButtonIconWidget?-Custom send button icon
recorderStartButtonIconWidget?-Custom icon for media recorder start button
recorderPauseButtonIconWidget?-Custom icon for media recorder pause button
recorderDeleteButtonIconWidget?-Custom icon for media recorder delete button
recorderStopButtonIconWidget?-Custom icon for media recorder stop button
recorderSendButtonIconWidget?-Custom icon for media recorder send button
disableMentionAllboolfalseDisables @all mentions in groups
mentionAllLabelString?-Custom label for group mentions
mentionAllLabelIdString?-Custom label ID for group mentions
headerViewComposerWidgetBuilder?-Custom header view
footerViewComposerWidgetBuilder?-Custom footer view
textFormattersList<CometChatTextFormatter>?-List of text formatters
stateCallBackFunction(CometChatMessageComposerController)?-Callback to access controller functions