Skip to main content
{
  "component": "CometChatSearch",
  "package": "cometchat_chat_uikit",
  "import": "import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';",
  "description": "A powerful search interface that allows users to search across conversations and messages in real time with filters and customization options",
  "primaryOutput": {
    "prop": "onMessageClicked",
    "type": "void Function(BaseMessage message)"
  },
  "props": {
    "data": {
      "user": {
        "type": "User?",
        "default": "null",
        "note": "User object for user message search"
      },
      "group": {
        "type": "Group?",
        "default": "null",
        "note": "Group object for group message search"
      },
      "searchFilters": {
        "type": "List<SearchFilter>?",
        "default": "null",
        "note": "List of filters to be shown in the search screen"
      },
      "searchIn": {
        "type": "List<SearchScope>?",
        "default": "null",
        "note": "List of scopes to be shown in the search result"
      }
    },
    "callbacks": {
      "onBack": "VoidCallback?",
      "onConversationClicked": "void Function(Conversation conversation)?",
      "onMessageClicked": "void Function(BaseMessage message)?",
      "onError": "OnError?",
      "onConversationsLoad": "OnLoad<Conversation>?",
      "onMessagesLoad": "OnLoad<BaseMessage>?",
      "onEmpty": "OnEmpty?"
    },
    "visibility": {
      "usersStatusVisibility": {
        "type": "bool?",
        "default": "null"
      },
      "receiptsVisibility": {
        "type": "bool?",
        "default": "null"
      },
      "groupTypeVisibility": {
        "type": "bool?",
        "default": "null"
      }
    },
    "viewSlots": {
      "loadingStateView": "WidgetBuilder?",
      "errorStateView": "WidgetBuilder?",
      "emptyStateView": "WidgetBuilder?",
      "initialStateView": "WidgetBuilder?",
      "conversationItemView": "Widget? Function(BuildContext, Conversation)?",
      "conversationTitleView": "Widget? Function(BuildContext, Conversation)?",
      "conversationLeadingView": "Widget? Function(BuildContext, Conversation)?",
      "conversationSubtitleView": "Widget? Function(BuildContext, Conversation)?",
      "conversationTailView": "Widget? Function(BuildContext, Conversation)?",
      "searchTextMessageView": "Widget? Function(BuildContext, TextMessage)?",
      "searchImageMessageView": "Widget? Function(BuildContext, MediaMessage)?",
      "searchVideoMessageView": "Widget? Function(BuildContext, MediaMessage)?",
      "searchFileMessageView": "Widget? Function(BuildContext, MediaMessage)?",
      "searchAudioMessageView": "Widget? Function(BuildContext, MediaMessage)?",
      "searchMessageLinkView": "Widget? Function(BuildContext, BaseMessage)?"
    },
    "formatting": {
      "dateSeparatorFormatterCallback": {
        "type": "DateTimeFormatterCallback?",
        "default": "null"
      },
      "timeSeparatorFormatterCallback": {
        "type": "DateTimeFormatterCallback?",
        "default": "null"
      }
    }
  },
  "events": [],
  "sdkListeners": [],
  "compositionExample": {
    "description": "CometChatSearch can be used standalone or embedded within other screens",
    "components": ["CometChatConversations", "CometChatMessageList"],
    "flow": "User searches → Results displayed → User clicks result → Navigate to conversation/message"
  },
  "types": {
    "SearchFilter": {
      "label": "String",
      "icon": "Widget?"
    },
    "SearchScope": {
      "conversations": "bool",
      "messages": "bool"
    }
  }
}

Where It Fits

CometChatSearch is a full-screen search experience that allows users to find messages, conversations, media, and more through an intuitive and filterable search interface. It can be embedded in multiple contexts — as part of the conversation list, message header, or as a standalone full-screen search experience.

Minimal Render

The simplest way to render CometChatSearch:
import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';
import 'package:flutter/material.dart';

// Using Navigator to launch CometChatSearch
Navigator.push(
  context, 
  MaterialPageRoute(builder: (context) => CometChatSearch())
);
You can also embed it as a widget:
import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';
import 'package:flutter/material.dart';

class SearchScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: CometChatSearch(),
      ),
    );
  }
}

Filtering

Use the request builder props to filter which items appear in the search results.

ConversationsRequestBuilder

Filter conversations in the search results:
CometChatSearch(
  conversationsRequestBuilder: ConversationsRequestBuilder()
    ..limit = 30,
)

MessagesRequestBuilder

Filter messages in the search results:
CometChatSearch(
  messagesRequestBuilder: MessagesRequestBuilder()
    ..limit = 50,
)
Search within a specific user or group conversation:
// Search within a specific user's conversation
CometChatSearch(
  user: user,
)

// Search within a specific group's conversation
CometChatSearch(
  group: group,
)

Actions and Events

Callback Props

Component-level callbacks that fire on specific user interactions:
CallbackSignatureFires When
onConversationClickedvoid Function(Conversation conversation)?User clicks a conversation from search results
onMessageClickedvoid Function(BaseMessage message)?User clicks a message from search results
onBackVoidCallback?User clicks the back button
onErrorOnError?An error occurs in the component
onConversationsLoadOnLoad<Conversation>?Conversations are loaded
onMessagesLoadOnLoad<BaseMessage>?Messages are loaded
onEmptyOnEmpty?Search results are empty
CometChatSearch(
  onConversationClicked: (conversation) {
    // Navigate to the conversation
    print('Conversation clicked: ${conversation.conversationId}');
  },
  onMessageClicked: (message) {
    // Navigate to the message
    print('Message clicked: ${message.id}');
  },
  onBack: () {
    Navigator.pop(context);
  },
  onError: (e) {
    print('Error: $e');
  },
)

Global UI Events

The CometChatSearch component does not produce any global UI events.

Custom View Slots

Customize the appearance of CometChatSearch by replacing default views with your own widgets.

State Views

SlotSignatureReplaces
loadingStateViewWidgetBuilder?Loading spinner
emptyStateViewWidgetBuilder?Empty state display
errorStateViewWidgetBuilder?Error state display
initialStateViewWidgetBuilder?Initial state before search

Conversation View Slots

SlotSignatureReplaces
conversationItemViewWidget? Function(BuildContext, Conversation)?Entire conversation list item
conversationLeadingViewWidget? Function(BuildContext, Conversation)?Avatar / left section
conversationTitleViewWidget? Function(BuildContext, Conversation)?Name / title text
conversationSubtitleViewWidget? Function(BuildContext, Conversation)?Secondary text / preview
conversationTailViewWidget? Function(BuildContext, Conversation)?Right section / timestamp

Message View Slots

SlotSignatureReplaces
searchTextMessageViewWidget? Function(BuildContext, TextMessage)?Text message item
searchImageMessageViewWidget? Function(BuildContext, MediaMessage)?Image message item
searchVideoMessageViewWidget? Function(BuildContext, MediaMessage)?Video message item
searchFileMessageViewWidget? Function(BuildContext, MediaMessage)?File message item
searchAudioMessageViewWidget? Function(BuildContext, MediaMessage)?Audio message item
searchMessageLinkViewWidget? Function(BuildContext, BaseMessage)?Link message item

Example: Custom Text Message View

CometChatSearch(
  searchTextMessageView: (context, message) {
    String senderName = message.sender?.name ?? "Unknown";
    return Container(
      padding: const EdgeInsets.all(16),
      width: double.infinity,
      color: const Color(0xFFE8E4F3),
      child: Row(
        children: [
          Text(
            "$senderName: ",
            style: const TextStyle(
              color: Color(0xFF6B4FBB),
              fontSize: 16,
              fontWeight: FontWeight.bold,
            ),
          ),
          Expanded(
            child: Text(
              message.text,
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: const TextStyle(
                color: Color(0xFF4A4A4A),
                fontSize: 16,
              ),
            ),
          ),
        ],
      ),
    );
  },
)

Icon Customization

PropTypeDescription
searchBackIconWidget?Custom back icon
searchClearIconWidget?Custom clear icon

Styling

Customize the appearance of CometChatSearch using CometChatSearchStyle.
CometChatSearch(
  searchStyle: CometChatSearchStyle(
    backgroundColor: const Color(0xFFEDEAFA),
    searchBackgroundColor: Colors.white,
    searchTextColor: Colors.black,
    searchPlaceHolderTextColor: Colors.grey,
    
    // Filter chip styling
    searchFilterChipBackgroundColor: Colors.grey[200],
    searchFilterChipSelectedBackgroundColor: Colors.purple,
    searchFilterChipTextColor: Colors.black,
    searchFilterChipSelectedTextColor: Colors.white,
    
    // Conversation item styling
    searchConversationItemBackgroundColor: const Color(0xFFEDEAFA),
    searchConversationTitleTextStyle: const TextStyle(fontWeight: FontWeight.bold),
    searchConversationSubTitleTextStyle: const TextStyle(color: Colors.grey),
    
    // Message item styling
    searchMessageItemBackgroundColor: const Color(0xFFEDEAFA),
    searchMessageTitleTextStyle: const TextStyle(fontWeight: FontWeight.bold),
    
    // See more button
    searchSeeMoreColor: Colors.purple,
  ),
)

Style Properties

PropertyTypeDescription
backgroundColorColor?Background color of the search component
searchBackgroundColorColor?Background color of the search text field
searchBorderBorderSide?Border of the search text field
searchBorderRadiusBorderRadius?Border radius of the search text field
searchTextColorColor?Color of the search text
searchTextStyleTextStyle?Style of the search text
searchPlaceHolderTextColorColor?Color of the placeholder text
searchPlaceHolderTextStyleTextStyle?Style of the placeholder text
searchBackIconColorColor?Color of the back icon
searchClearIconColorColor?Color of the clear icon
searchFilterChipBackgroundColorColor?Background color of filter chips
searchFilterChipSelectedBackgroundColorColor?Background color of selected filter chips
searchFilterChipTextColorColor?Text color of filter chips
searchFilterChipTextStyleTextStyle?Text style of filter chips
searchFilterChipSelectedTextColorColor?Text color of selected filter chips
searchFilterChipSelectedTextStyleTextStyle?Text style of selected filter chips
searchFilterIconColorColor?Color of filter icons
searchFilterSelectedIconColorColor?Color of selected filter icons
searchFilterChipBorderBorder?Border of filter chips
searchFilterChipSelectedBorderBorder?Border of selected filter chips
searchFilterChipBorderRadiusBorderRadius?Border radius of filter chips
searchSectionHeaderTextColorColor?Color of section header text
searchSectionHeaderTextStyleTextStyle?Style of section header text
searchConversationItemBackgroundColorColor?Background color of conversation items
searchConversationTitleTextColorColor?Text color of conversation titles
searchConversationTitleTextStyleTextStyle?Style of conversation titles
searchConversationSubTitleTextStyleTextStyle?Style of conversation subtitles
searchConversationTitleSubTextColorColor?Text color of conversation subtitles
searchConversationDateTextColorColor?Text color of conversation dates
searchConversationDateTextStyleTextStyle?Style of conversation dates
searchMessageItemBackgroundColorColor?Background color of message items
searchMessageTitleTextColorColor?Text color of message titles
searchMessageTitleTextStyleTextStyle?Style of message titles
searchMessageSubTitleTextColorColor?Text color of message subtitles
searchMessageSubTitleTextStyleTextStyle?Style of message subtitles
searchMessageTimeStampStyleCometChatDateStyle?Style of message timestamps
searchMessageDateSeparatorStyleCometChatDateStyle?Style of date separators
searchEmptyStateTextColorColor?Text color for empty state
searchEmptyStateTextStyleTextStyle?Style for empty state text
searchEmptyStateSubtitleColorColor?Color for empty state subtitle
searchEmptyStateSubtitleStyleTextStyle?Style for empty state subtitle
searchErrorStateTextColorColor?Text color for error state
searchErrorStateTextStyleTextStyle?Style for error state text
searchErrorStateSubtitleColorColor?Color for error state subtitle
searchErrorStateSubtitleStyleTextStyle?Style for error state subtitle
searchSeeMoreColorColor?Color of “See More” button
searchSeeMoreStyleTextStyle?Style of “See More” button
avatarStyleCometChatAvatarStyle?Style for avatars
badgeStyleCometChatBadgeStyle?Style for badges

Props Reference

PropTypeDefaultDescription
userUser?nullUser object for scoped search
groupGroup?nullGroup object for scoped search
searchFiltersList<SearchFilter>?nullList of filters to show
searchInList<SearchScope>?nullList of search scopes
usersStatusVisibilitybool?nullShow/hide user status indicator
receiptsVisibilitybool?nullShow/hide message receipts
groupTypeVisibilitybool?nullShow/hide group type icon
onBackVoidCallback?nullBack button callback
onConversationClickedFunction(Conversation)?nullConversation click callback
onMessageClickedFunction(BaseMessage)?nullMessage click callback
onErrorOnError?nullError callback
onConversationsLoadOnLoad<Conversation>?nullConversations load callback
onMessagesLoadOnLoad<BaseMessage>?nullMessages load callback
onEmptyOnEmpty?nullEmpty state callback
loadingStateViewWidgetBuilder?nullCustom loading view
errorStateViewWidgetBuilder?nullCustom error view
emptyStateViewWidgetBuilder?nullCustom empty view
initialStateViewWidgetBuilder?nullCustom initial view
conversationItemViewWidget? Function(BuildContext, Conversation)?nullCustom conversation item
conversationTitleViewWidget? Function(BuildContext, Conversation)?nullCustom conversation title
conversationLeadingViewWidget? Function(BuildContext, Conversation)?nullCustom conversation leading view
conversationSubtitleViewWidget? Function(BuildContext, Conversation)?nullCustom conversation subtitle
conversationTailViewWidget? Function(BuildContext, Conversation)?nullCustom conversation tail view
searchTextMessageViewWidget? Function(BuildContext, TextMessage)?nullCustom text message view
searchImageMessageViewWidget? Function(BuildContext, MediaMessage)?nullCustom image message view
searchVideoMessageViewWidget? Function(BuildContext, MediaMessage)?nullCustom video message view
searchFileMessageViewWidget? Function(BuildContext, MediaMessage)?nullCustom file message view
searchAudioMessageViewWidget? Function(BuildContext, MediaMessage)?nullCustom audio message view
searchMessageLinkViewWidget? Function(BuildContext, BaseMessage)?nullCustom link message view
searchBackIconWidget?nullCustom back icon
searchClearIconWidget?nullCustom clear icon
dateSeparatorFormatterCallbackDateTimeFormatterCallback?nullDate separator formatter
timeSeparatorFormatterCallbackDateTimeFormatterCallback?nullTime separator formatter
conversationsProtocolConversationsBuilderProtocol?nullConversations builder protocol
conversationsRequestBuilderConversationsRequestBuilder?nullConversations request builder
messagesRequestBuilderMessagesRequestBuilder?nullMessages request builder
searchStyleCometChatSearchStyle?nullStyle configuration