Skip to main content
{
  "component": "CometChatMessageList",
  "package": "cometchat_chat_uikit",
  "import": "import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';",
  "description": "A composite widget that displays a list of messages with real-time operations. Includes various message types such as Text Messages, Media Messages, Stickers, and more.",
  "primaryOutput": {
    "prop": "onThreadRepliesClick",
    "type": "void Function(BaseMessage, BuildContext, {CometChatMessageTemplate?})?"
  },
  "props": {
    "data": {
      "user": {
        "type": "User?",
        "default": "null",
        "note": "User object for user message list (one of user or group is required)"
      },
      "group": {
        "type": "Group?",
        "default": "null",
        "note": "Group object for group message list (one of user or group is required)"
      },
      "messagesRequestBuilder": {
        "type": "MessagesRequestBuilder?",
        "default": "null",
        "note": "Custom request builder for filtering messages"
      },
      "templates": {
        "type": "List<CometChatMessageTemplate>?",
        "default": "null",
        "note": "Message templates for the list"
      }
    },
    "callbacks": {
      "onThreadRepliesClick": "void Function(BaseMessage, BuildContext, {CometChatMessageTemplate?})?",
      "onError": "OnError?",
      "onLoad": "OnLoad<BaseMessage>?",
      "onEmpty": "OnEmpty?",
      "onReactionClick": "Function(String?, BaseMessage)?",
      "onReactionLongPress": "Function(String?, BaseMessage)?",
      "onReactionListItemClick": "Function(String?, BaseMessage?)?"
    },
    "visibility": {
      "hideTimestamp": { "type": "bool?", "default": null },
      "avatarVisibility": { "type": "bool?", "default": true },
      "receiptsVisibility": { "type": "bool?", "default": true },
      "disableReactions": { "type": "bool?", "default": false },
      "hideStickyDate": { "type": "bool?", "default": false },
      "hideReplyInThreadOption": { "type": "bool?", "default": false },
      "hideEditMessageOption": { "type": "bool?", "default": false },
      "hideDeleteMessageOption": { "type": "bool?", "default": false },
      "hideGroupActionMessages": { "type": "bool?", "default": false }
    },
    "sound": {
      "disableSoundForMessages": { "type": "bool?", "default": null },
      "customSoundForMessages": { "type": "String?", "default": null }
    },
    "viewSlots": {
      "loadingStateView": "WidgetBuilder?",
      "emptyStateView": "WidgetBuilder?",
      "errorStateView": "WidgetBuilder?",
      "headerView": "Widget? Function(BuildContext, {User?, Group?, int?})?",
      "footerView": "Widget? Function(BuildContext, {User?, Group?, int?})?"
    },
    "formatting": {
      "alignment": { "type": "ChatAlignment", "default": "ChatAlignment.standard" },
      "datePattern": { "type": "String Function(BaseMessage)?", "default": null },
      "dateSeparatorPattern": { "type": "String Function(DateTime)?", "default": null }
    }
  },
  "events": [],
  "sdkListeners": [
    "onMessageReceived",
    "onMessageEdited",
    "onMessageDeleted",
    "onTypingStarted",
    "onTypingEnded"
  ],
  "compositionExample": {
    "description": "CometChatMessageList is typically used within CometChatMessages, paired with CometChatMessageHeader and CometChatMessageComposer",
    "components": ["CometChatMessageHeader", "CometChatMessageComposer", "CometChatMessages"],
    "flow": "User/Group → MessageList displays messages → Real-time updates via SDK listeners"
  },
  "types": {
    "CometChatMessageListStyle": {
      "backgroundColor": "Color?",
      "border": "BoxBorder?",
      "borderRadius": "BorderRadiusGeometry?",
      "incomingMessageBubbleStyle": "CometChatIncomingMessageBubbleStyle?",
      "outgoingMessageBubbleStyle": "CometChatOutgoingMessageBubbleStyle?",
      "avatarStyle": "CometChatAvatarStyle?"
    }
  }
}

Where It Fits

CometChatMessageList is a Composite Widget that displays a list of messages and effectively manages real-time operations. It includes various types of messages such as Text Messages, Media Messages, Stickers, and more. CometChatMessageList is primarily a list of the base widget MessageBubble. The MessageBubble Widget is utilized to create different types of chat bubbles depending on the message type.
import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';

// CometChatMessageList is typically used within CometChatMessages
// or as part of a custom 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 CometChatMessageList:
import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';

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

// For a group conversation
CometChatMessageList(
  group: group,
)
Simply adding the MessageList component to the layout will only display the loading indicator. To fetch messages for a specific entity, you need to supplement it with User or Group Object.

Filtering CometChatMessageList

Use the messagesRequestBuilder prop to filter which messages appear in the list.

Filter Recipes

RecipeCode
Limit messagesMessagesRequestBuilder()..limit = 30
Search messagesMessagesRequestBuilder()..searchKeyword = "keyword"
Filter by typeMessagesRequestBuilder()..types = ["text"]
Filter by categoryMessagesRequestBuilder()..categories = ["message"]
CometChatMessageList(
  user: user,
  messagesRequestBuilder: MessagesRequestBuilder()
    ..uid = user.uid
    ..searchKeyword = "searchKeyword"
    ..limit = 30,
)
The following parameters in messageRequestBuilder will always be altered inside the message list:
  1. UID
  2. GUID
  3. types
  4. categories
For the full MessagesRequestBuilder API, see the SDK documentation.

Actions and Events

Callback Props

Component-level callbacks that fire on specific user interactions:
CallbackSignatureFires When
onThreadRepliesClickvoid Function(BaseMessage, BuildContext, {CometChatMessageTemplate?})?User clicks on thread indicator
onErrorOnError?An error occurs while fetching messages
onLoadOnLoad<BaseMessage>?List is successfully fetched and loaded
onEmptyOnEmpty?List is empty
onReactionClickFunction(String?, BaseMessage)?User clicks on a reaction pill
onReactionLongPressFunction(String?, BaseMessage)?User long presses on a reaction pill
onReactionListItemClickFunction(String?, BaseMessage?)?User clicks on a reaction list item
addMoreReactionTapFunction(BaseMessage)?User clicks “Add More Reactions” button
CometChatMessageList(
  user: user,
  onThreadRepliesClick: (message, context, {template}) {
    // Handle thread replies click
  },
  onError: (e) {
    // Handle error
  },
  onLoad: (list) {
    print("Messages loaded: ${list.length}");
  },
  onEmpty: () {
    print("No messages");
  },
  onReactionClick: (emoji, message) {
    // Handle reaction click
  },
)

SDK Events (Real-Time, Automatic)

The component automatically handles these SDK listeners for real-time updates:
SDK ListenerHandled Automatically
onMessageReceivedAdds new message to the list
onMessageEditedUpdates edited message in the list
onMessageDeletedRemoves deleted message from the list
onTypingStartedShows typing indicator
onTypingEndedHides typing indicator

Custom View Slots

Customize the appearance of CometChatMessageList by replacing default views with your own widgets.
SlotSignatureReplaces
loadingStateViewWidgetBuilder?Loading spinner
emptyStateViewWidgetBuilder?Empty state display
errorStateViewWidgetBuilder?Error state display
headerViewWidget? Function(BuildContext, {User?, Group?, int?})?Header section
footerViewWidget? Function(BuildContext, {User?, Group?, int?})?Footer section
emptyChatGreetingViewWidgetBuilder?Empty chat greeting for AI
newMessageIndicatorViewWidgetBuilder?New message indicator

Example: Custom Header View

CometChatMessageList(
  user: user,
  headerView: (context, {group, parentMessageId, user}) {
    return Container(
      width: double.maxFinite,
      color: Color(0xFFEDEAFA),
      padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
      child: Row(
        children: [
          Icon(Icons.notes_outlined, color: Color(0xFF6852D6)),
          SizedBox(width: 8),
          Text('Notes', style: TextStyle(color: Color(0xFF6852D6))),
        ],
      ),
    );
  },
)
CometChatMessageList(
  user: user,
  footerView: (context, {group, parentMessageId, user}) {
    return Container(
      width: double.maxFinite,
      color: Color(0xFFEDEAFA),
      padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
      child: Row(
        children: [
          Icon(Icons.sunny, color: Color(0xFF6852D6)),
          SizedBox(width: 8),
          Text('Ice Breakers', style: TextStyle(color: Color(0xFF6852D6))),
        ],
      ),
    );
  },
)

Example: Custom Loading State View

CometChatMessageList(
  user: user,
  loadingStateView: (context) {
    return Center(
      child: CircularProgressIndicator(),
    );
  },
)

Example: Custom Empty State View

CometChatMessageList(
  user: user,
  emptyStateView: (context) {
    return Center(
      child: Text("No messages yet. Start the conversation!"),
    );
  },
)

Example: Custom Error State View

CometChatMessageList(
  user: user,
  errorStateView: (context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text("Couldn't load messages"),
          ElevatedButton(
            onPressed: () {
              // Retry logic
            },
            child: Text("Retry"),
          ),
        ],
      ),
    );
  },
)

Styling

Customize the appearance of CometChatMessageList using CometChatMessageListStyle.

Style Properties

PropertyTypeDescription
backgroundColorColor?Background color of the message list
borderBoxBorder?Border of the message list
borderRadiusBorderRadiusGeometry?Border radius of the message list
avatarStyleCometChatAvatarStyle?Style for avatar in message bubble
emptyStateTextStyleTextStyle?Style for empty state text
emptyStateTextColorColor?Color for empty state text
emptyStateSubtitleStyleTextStyle?Style for empty state subtitle
emptyStateSubtitleColorColor?Color for empty state subtitle
errorStateTextStyleTextStyle?Style for error state text
errorStateTextColorColor?Color for error state text
errorStateSubtitleStyleTextStyle?Style for error state subtitle
errorStateSubtitleColorColor?Color for error state subtitle
incomingMessageBubbleStyleCometChatIncomingMessageBubbleStyle?Style for incoming message bubble
outgoingMessageBubbleStyleCometChatOutgoingMessageBubbleStyle?Style for outgoing message bubble
messageInformationStyleCometChatMessageInformationStyle?Style for message information
messageOptionSheetStyleCometChatMessageOptionSheetStyle?Style for message option sheet
mentionsStyleCometChatMentionsStyle?Style for mentions
actionBubbleStyleCometChatActionBubbleStyle?Style for group action bubbles
reactionListStyleCometChatReactionListStyle?Style for reaction list
reactionsStyleCometChatReactionsStyle?Style for reactions
aiSmartRepliesStyleCometChatAISmartRepliesStyle?Style for smart replies
aiConversationStarterStyleCometChatAIConversationStarterStyle?Style for conversation starter
aiConversationSummaryStyleCometChatAIConversationSummaryStyle?Style for conversation summary
aiAssistantSuggestedMessageTextStyleTextStyle?Text style for AI suggested messages
aiAssistantSuggestedMessageTextColorColor?Text color for AI suggested messages
aiAssistantSuggestedMessageBorderBorder?Border for AI suggested messages
aiAssistantSuggestedMessageBorderRadiusBorderRadius?Border radius for AI suggested messages
aiAssistantSuggestedMessageBackgroundColorColor?Background color for AI suggested messages
aiAssistantSuggestedMessageIconColorColor?Icon color for AI suggested messages
emptyChatGreetingTitleTextColorColor?Text color for empty chat greeting title
emptyChatGreetingTitleTextStyleTextStyle?Text style for empty chat greeting title
emptyChatGreetingSubtitleTextColorColor?Text color for empty chat greeting subtitle
emptyChatGreetingSubtitleTextStyleTextStyle?Text style for empty chat greeting subtitle
flagMessageStyleCometchatFlagMessageStyle?Style for flag message dialog
newMessageIndicatorStyleCometChatNewMessageIndicatorStyle?Style for new message indicator

Example: Custom Styling

CometChatMessageList(
  user: user,
  style: CometChatMessageListStyle(
    backgroundColor: Color(0xFFFEEDE1),
    outgoingMessageBubbleStyle: CometChatOutgoingMessageBubbleStyle(
      backgroundColor: Color(0xFFF76808),
    ),
  ),
)

Example: Custom Avatar Style

CometChatMessageList(
  user: user,
  style: CometChatMessageListStyle(
    avatarStyle: CometChatAvatarStyle(
      border: Border.all(width: 5),
      borderRadius: 20,
      backgroundColor: Colors.red,
    ),
  ),
)

Example: Custom Mentions Style

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

Advanced

Message Templates

CometChatMessageTemplate is a pre-defined structure for creating message views that can be used as a starting point or blueprint for creating message bubbles.
List<CometChatMessageTemplate> getTemplate() {
  // Creating a text template
  CometChatMessageTemplate textTemplate = ChatConfigurator.getDataSource().getTextMessageTemplate();
  textTemplate.contentView = (BaseMessage baseMessage, BuildContext buildContext, BubbleAlignment alignment, {AdditionalConfigurations? additionalConfigurations}) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Text(
        (baseMessage as TextMessage).text,
        style: TextStyle(
          color: alignment == BubbleAlignment.left ? Colors.deepPurple : Colors.yellow,
          fontSize: 14,
          fontWeight: FontWeight.bold,
        ),
      ),
    );
  };

  // Creating a custom message template
  CometChatMessageTemplate customMessageTemplate = CometChatMessageTemplate(
    type: 'custom_template',
    category: 'custom_category',
    bubbleView: (message, context, alignment) => const Text('Custom message'),
  );

  return [textTemplate, customMessageTemplate];
}

// Usage
CometChatMessageList(
  user: user,
  templates: getTemplate(),
)
Image

Date Separator Pattern

Customize the date separator pattern:
CometChatMessageList(
  user: user,
  dateSeparatorPattern: (DateTime dateTime) {
    return DateFormat("dd/MM/yyyy").format(dateTime);
  },
)
Image

Date Pattern

Customize the date pattern for message receipts:
CometChatMessageList(
  user: user,
  datePattern: (message) {
    return DateFormat('EEE, M/d/y').format(message.sentAt!);
  },
)
Image

Props Reference

PropTypeDefaultDescription
userUser?nullUser object for user message list
groupGroup?nullGroup object for group message list
messagesRequestBuilderMessagesRequestBuilder?nullCustom request builder for filtering
styleCometChatMessageListStyle?-Sets style for message list
scrollControllerScrollController?-Controller for the message list
emptyStateTextString?-Text when list is empty
errorStateTextString?-Text when error occurs
loadingStateViewWidgetBuilder?-View for loading state
emptyStateViewWidgetBuilder?-View for empty state
errorStateViewWidgetBuilder?-View for error state
disableSoundForMessagesbool?nullDisables sound for messages
customSoundForMessagesString?nullCustom sound URL
readIconWidget?-Custom read icon
deliveredIconWidget?-Custom delivered icon
sentIconWidget?-Custom sent icon
waitIconWidget?-Custom wait icon
alignmentChatAlignmentstandardChat alignment setting
avatarVisibilitybool?trueToggle avatar visibility
datePatternString Function(BaseMessage)?-Custom date pattern
hideTimestampbool?nullToggle timestamp visibility
templatesList<CometChatMessageTemplate>?-Message templates
onThreadRepliesClickThreadRepliesClick?-Thread replies callback
headerViewWidget? Function(...)?-Custom header view
footerViewWidget? Function(...)?-Custom footer view
dateSeparatorPatternString Function(DateTime)?-Date separator pattern
onErrorOnError?-Error callback
receiptsVisibilitybool?trueToggle read receipts
dateSeparatorStyleCometChatDateStyle?-Date separator style
disableReactionsbool?falseToggle reactions
addReactionIconWidget?-Custom add reaction icon
favoriteReactionsList<String>?-Frequently used reactions
textFormattersList<CometChatTextFormatter>?-Text formatters
disableMentionsbool?nullDisable mentions
paddingEdgeInsetsGeometry?-Padding for message list
marginEdgeInsetsGeometry?-Margin for message list
widthdouble?-Width of message list
heightdouble?-Height of message list
onLoadOnLoad<BaseMessage>?-Load callback
onEmptyOnEmpty?-Empty callback
onReactionClickFunction(String?, BaseMessage)?-Reaction click callback
onReactionLongPressFunction(String?, BaseMessage)?-Reaction long press callback
hideStickyDatebool?falseHide sticky date
hideReplyInThreadOptionbool?falseHide reply in thread option
hideTranslateMessageOptionbool?falseHide translate option
hideEditMessageOptionbool?falseHide edit option
hideDeleteMessageOptionbool?falseHide delete option
hideReactionOptionbool?falseHide reaction option
hideMessagePrivatelyOptionbool?falseHide message privately option
hideCopyMessageOptionbool?falseHide copy option
hideMessageInfoOptionbool?falseHide message info option
hideGroupActionMessagesbool?falseHide group action messages
enableConversationStartersbool?falseEnable conversation starters
enableSmartRepliesbool?falseEnable smart replies
hideShareMessageOptionbool?falseHide share option
smartRepliesDelayDurationint?10000Smart replies delay (ms)
smartRepliesKeywordsList<String>?-Smart replies keywords
addTemplateList<CometChatMessageTemplate>?-Add custom templates
dateTimeFormatterCallbackDateTimeFormatterCallback?-Date time formatter
hideModerationViewbool?nullHide moderation view
hideThreadViewbool?nullHide thread view
suggestedMessagesList<String>?-AI assistant suggestions
hideSuggestedMessagesbool?falseHide suggested messages
emptyChatGreetingViewWidgetBuilder?-Empty chat greeting view
setAiAssistantToolsMap<String, Function(String?)>?-AI assistant tools
streamingSpeedint?-AI streaming speed
hideDateSeparatorbool?falseHide date separator
mentionAllLabelString?-Group mention label
mentionAllLabelIdString?-Group mention label ID
hideFlagOptionbool?falseHide report option
hideFlagRemarkFieldbool?falseHide flag remark field
startFromUnreadMessagesbool?falseStart from unread messages
showMarkAsUnreadOptionbool?falseShow mark as unread option
newMessageIndicatorViewWidgetBuilder?-New message indicator view
enableConversationSummarybool?falseEnable conversation summary
generateConversationSummarybool?falseGenerate conversation summary
hideReplyOptionbool?falseHide reply option
flagReasonLocalizerString Function(String)?-Flag reason localizer
reactionsRequestBuilderReactionsRequestBuilder?-Request builder for reactions
stateCallBackFunction(CometChatMessageListController)?-Callback to access controller
customSoundForMessagePackageString?-Package name for custom sound
messageIdint?-Specific message ID to scroll to