AI Integration Quick Reference
AI Integration Quick Reference
CometChatConversations renders a scrollable list of recent conversations with real-time updates for new messages, typing indicators, read receipts, and user presence.
Where It Fits
CometChatConversations is a list component. It renders recent conversations and emits the selected Conversation via onItemTap. Wire it to CometChatMessageHeader, CometChatMessageList, and CometChatMessageComposer to build a standard chat layout.
- Dart
Quick Start
Using Navigator:- Dart
- Dart
CometChatUIKit.init(), a user logged in, and the UI Kit dependency added.
Filtering Conversations
Pass aConversationsRequestBuilder to control what loads:
- Dart
Filter Recipes
Actions and Events
Callback Methods
onItemTap
Fires when a conversation row is tapped. Primary navigation hook.
- Dart
onItemLongPress
Fires when a conversation row is long-pressed. By default the row opens a context menu with Pin / Unpin (v6.1.1 and later, when pinConversationOptionVisibility is not false) and Delete (when deleteConversationOptionVisibility is true). Setting this callback replaces that menu.
- Dart
onBack
Fires when the user presses the back button in the app bar.
- Dart
onSelection
Fires when conversations are selected/deselected in multi-select mode.
- Dart
onError
Fires on internal errors (network failure, auth issue, SDK exception).
- Dart
onLoad
Fires when the list is successfully fetched and loaded.
- Dart
onEmpty
Fires when the list is empty after loading.
- Dart
Global Events
The component emits events viaCometChatConversationEvents that can be subscribed to from anywhere:
- Dart
SDK Events (Real-Time, Automatic)
The component listens to these SDK events internally. No manual setup needed.Functionality
Custom View Slots
Leading View
Replace the avatar / left section.Conversation.conversationWith is an AppEntity (a User or a Group), so it has no .name.
Narrow the type before reading a display name. The snippets below use this helper:- Dart
Title View
Replace the name / title text.- Dart
Subtitle View
Replace the last message preview.- Dart
Trailing View
Replace the timestamp / badge / right section.- Dart
List Item View
Replace the entire list item row.- Dart
State Views
- Dart
Menu Options
- Dart
Pin Conversations
Available since v6.1.1 Long-pressing a row opens a context menu with Pin / Unpin alongside Delete. Pinned rows show a pin icon and form a shelf at the top of the list, ordered system pins first (placed by an admin surface,pinnedBy == "app_system"), then the user’s own pins, then the remaining conversations by latest activity. Real-time events keep that ordering: new activity moves a conversation to the top of its own section only, never above a pin.
Everything is wired through the SDK’s Pin A Conversation APIs: the component performs the pin/unpin call, shows a “Conversation pinned” / “Conversation unpinned” toast — or, at the cap, “You can only pin N chats. Unpin one to pin another.” with the server’s limit — and reorders the list from the SDK’s ConversationListener events, including pins made from the user’s other devices.
The option is offered on unpinned rows and on rows the logged-in user pinned. It is withheld from rows pinned by anyone else — app_system or another UID — which keep the pin icon but cannot be unpinned from the client. It also hides itself when CometChat.isPinConversationEnabled() returns false. To hide it regardless, set pinConversationOptionVisibility to false.
Passing your own
onItemLongPress replaces the built-in context menu, Pin and Delete included. From v6.2.0, setOptions also replaces the built-in Pin and Delete entries with the options you return, while addOptions keeps them and lists your options in front.- Dart
Common Patterns
Minimal list — hide all chrome
- Dart
Users-only conversations
- Dart
Custom date formatting
- Dart
Advanced
BLoC Access
Provide a customConversationsBloc to override behavior:
- Dart
Extending ConversationsBloc
ConversationsBloc uses the ListBase<Conversation> mixin with override hooks for custom list behavior:
- Dart
ListBase override hooks (onItemAdded, onItemRemoved, onItemUpdated, onListCleared, onListReplaced), see BLoC & Data — ListBase Hooks.
Public BLoC Events
Public BLoC Methods
Route Observer
Pass aRouteObserver to freeze rebuilds when another screen is pushed on top (prevents expensive rebuilds during keyboard animation):
- Dart
Style
- Dart
Style Properties
See Component Styling for the full reference.
Next Steps
Users
Browse and search available users
Message List
Display messages for a conversation
Component Styling
Detailed styling reference
Message Template
Customize message bubble structure