CometChatUsers renders a scrollable list of all available users with real-time presence updates, search, avatars, and online/offline status indicators.
Where It Fits
CometChatUsers is a list component. It renders all available users and emits the selected User via onItemTap. Wire it to CometChatMessageHeader, CometChatMessageList, and CometChatMessageComposer to build a direct messaging layout.
- Dart
Quick Start
Using Navigator:- Dart
- Dart
CometChatUIKit.init(), a user logged in, and the UI Kit dependency added.
Filtering Users
Pass aUsersRequestBuilder to control what loads:
- Dart
Filter Recipes
| Recipe | Builder property |
|---|---|
| Friends only | ..friendsOnly = true |
| Limit per page | ..limit = 10 |
| Search by keyword | ..searchKeyword = "john" |
| Hide blocked users | ..hideBlockedUsers = true |
| Filter by roles | ..roles = ["admin", "moderator"] |
| Filter by tags | ..tags = ["vip"] |
| Online users only | ..userStatus = CometChatConstants.userStatusOnline |
| Filter by UIDs | ..UIDs = ["uid1", "uid2"] |
Actions and Events
Callback Methods
onItemTap
Fires when a user row is tapped. Primary navigation hook.
- Dart
onItemLongPress
Fires when a user row is long-pressed.
- Dart
onBack
Fires when the user presses the back button in the app bar.
- Dart
onSelection
Fires when users are selected/deselected in multi-select mode.
- Dart
onError
Fires on internal errors.
- Dart
onLoad
Fires when the list is successfully fetched and loaded.
- Dart
onEmpty
Fires when the list is empty after loading.
- Dart
SDK Events (Real-Time, Automatic)
The component listens to these SDK events internally. No manual setup needed.| SDK Listener | Internal behavior |
|---|---|
onUserOnline | Updates online status indicator for the user |
onUserOffline | Updates offline status indicator for the user |
| Connection reconnected | Triggers silent refresh to sync user list |
Functionality
| Property | Type | Default | Description |
|---|---|---|---|
title | String? | null | Custom app bar title |
showBackButton | bool | true | Toggle back button |
hideAppbar | bool? | false | Toggle app bar visibility |
hideSearch | bool | false | Toggle search bar |
usersStatusVisibility | bool? | true | Show online/offline status indicator |
stickyHeaderVisibility | bool? | false | Show alphabetical sticky header |
selectionMode | SelectionMode? | null | Enable selection mode (single or multiple) |
searchPlaceholder | String? | null | Search placeholder text |
searchKeyword | String? | null | Pre-fill search keyword |
Custom View Slots
Leading View
Replace the avatar / left section.- Dart
Title View
Replace the name / title text.- Dart
Subtitle View
Replace the subtitle text below the user’s name.- Dart
Trailing View
Replace the right section of each user item.- Dart
List Item View
Replace the entire list item row.- Dart
State Views
- Dart
Common Patterns
Minimal list — hide all chrome
- Dart
Friends-only list
- Dart
Online users only
- Dart
Advanced
BLoC Access
Provide a customUsersBloc to override behavior:
- Dart
Extending UsersBloc
UsersBloc uses the ListBase<User> mixin with override hooks:
- Dart
ListBase override hooks (onItemAdded, onItemRemoved, onItemUpdated, onListCleared, onListReplaced), see BLoC & Data — ListBase Hooks.
Public BLoC Events
| Event | Description |
|---|---|
LoadUsers({searchKeyword, silent}) | Load initial users. silent: true keeps existing list visible. |
LoadMoreUsers() | Load next page (pagination) |
RefreshUsers() | Refresh the list |
SearchUsers(keyword) | Search users with debouncing |
ToggleUserSelection(uid) | Toggle selection state |
ClearUserSelection() | Clear all selections |
UpdateUser(user) | Update a specific user |
Public BLoC Methods
| Method | Returns | Description |
|---|---|---|
getStatusNotifier(uid) | ValueNotifier<String> | Per-user status notifier for isolated rebuilds |
getUserStatus(uid) | String | Current status for a user (online / offline) |
Style
- Dart
Style Properties
| Property | Description |
|---|---|
backgroundColor | List background color |
avatarStyle | Avatar appearance |
statusIndicatorStyle | Online/offline indicator |
searchBoxStyle | Search box appearance |
Next Steps
Conversations
Browse recent conversations
Groups
Browse and search available groups
Component Styling
Detailed styling reference
Message Template
Customize message bubble structure