Users
Overview
The CometChatUsers
is a Widget, showcasing an accessible list of all available users. It provides an integral search functionality, allowing you to locate any specific user swiftly and easily. For each user listed, the widget displays the user's name by default, in conjunction with their avatar when available. Furthermore, it includes a status indicator, visually informing you whether a user is currently online or offline.

The CometChatUsers
widget is composed of the following Base Widgets:
Widgets | Description |
---|---|
ListBase | a reusable container widget having title, search box, customisable background and a List View |
ListItem | a widget that renders data obtained from a User object on a Tile having a title, subtitle, leading and trailing view |
Usage
Integration
As CometChatUsers
is a custom widget, it can be launched directly by user actions such as button clicks or other interactions. It's also possible to integrate it into a tab widget. CometChatUsers
offers several parameters and methods for UI customization.
You can launch CometChatUsers
directly using Navigator.push
, or you can define it as a widget within the build
method of your State
class.
1. Using Navigator to Launch CometChatUsers
- Dart
Navigator.push(context, MaterialPageRoute(builder: (context) => const CometChatUsers()));
2. Embedding CometChatUsers
as a Widget in the build Method
- Dart
import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';
import 'package:flutter/material.dart';
class Users extends StatefulWidget {
const Users({super.key});
State<Users> createState() => _UsersState();
}
class _UsersState extends State<Users> {
Widget build(BuildContext context) {
return const Scaffold(
body: SafeArea(
child: CometChatUsers()
)
);
}
}
Actions
Actions dictate how a widget functions. They are divided into two types: Predefined and User-defined. You can override either type, allowing you to tailor the behavior of the widget to fit your specific needs.
onSelection
When the onSelection
event is triggered, it furnishes the list of selected users. This event can be invoked by any button or action within the interface. You have the flexibility to implement custom actions or behaviors based on the selected users.
This action does not come with any predefined behavior. However, you have the flexibility to override this event and tailor it to suit your needs using the following code snippet.
- Dart
CometChatUsers(
selectionMode: SelectionMode.multiple,
activateSelection: ActivateSelection.onClick,
onSelection: (list, context) {
//TODO: This action will trigger the end of selection.
},
)
onItemTap
The onItemTap
method is used to override the onClick behavior in CometChatUsers
.
This action does not come with any predefined behavior. However, you have the flexibility to override this event and tailor it to suit your needs using the following code snippet.
- Dart
CometChatUsers(
onItemTap: (context, user) {
// TODO("Not yet implemented")
},
)
onBack
This method allows users to override the onBack Pressed behavior in CometChatUsers
by utilizing the onBack
, providing customization options for handling the back action.
By default, this action has a predefined behavior: it simply dismisses the current widget. However, the flexibility of CometChat UI Kit allows you to override this standard behavior according to your application's specific requirements. You can define a custom action that will be performed instead when the back button is pressed.
- Dart
CometChatUsers(
onBack: () {
// TODO("Not yet implemented")
},
)
onError
This method onError
, allows users to override error handling within CometChatUsers
, providing greater control over error responses and actions.
- Dart
CometChatUsers(
onError: (e) {
// TODO("Not yet implemented")
},
)
onItemLongPress
This method onItemLongPress
, empowers users to customize long-click actions within CometChatUsers
, offering enhanced functionality and interaction possibilities.
- Dart
CometChatUsers(
onItemLongPress: (context, user) {
// TODO("Not yet implemented")
},
)
onLoad
Invoked when the list is successfully fetched and loaded, helping track component readiness.
- Dart
CometChatUsers(
onLoad: (list) {
// print("User List: $list");
},
)
onEmpty
Called when the list is empty, enabling custom handling such as showing a placeholder message.
- Dart
CometChatUsers(
onEmpty: () {
// print("User List is empty");
},
)
Filters
Filters allow you to customize the data displayed in a list within a Widget. You can filter the list based on your specific criteria, allowing for a more customized. Filters can be applied using RequestBuilders of Chat SDK.
1. UsersRequestBuilder
The UsersRequestBuilder enables you to filter and customize the user list based on available parameters in UsersRequestBuilder. This feature allows you to create more specific and targeted queries when fetching users. The following are the parameters available in UsersRequestBuilder
- Dart
CometChatUsers(
usersRequestBuilder: UsersRequestBuilder()
..limit = 10
)
Events
Events are emitted by a CometChatUsers
Widget. By using event you can extend existing functionality. Being global events, they can be applied in Multiple Locations and are capable of being Added or Removed.
To handle events supported by Users you have to add corresponding listeners by using CometChatUserEvents
Events | Description |
---|---|
ccUserBlocked | This will get triggered when the logged in user blocks another user |
ccUserUnblocked | This will get triggered when the logged in user unblocks another user |
- Dart
import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';
import 'package:flutter/material.dart';
class YourScreen extends StatefulWidget {
const YourScreen({super.key});
State<YourScreen> createState() => _YourScreenState();
}
class _YourScreenState extends State<YourScreen> with CometChatUserEventListener {
void initState() {
super.initState();
CometChatUserEvents.addUsersListener("listenerId", this);
}
void dispose(){
super.dispose();
CometChatUserEvents.removeUsersListener("listenerId");
}
void ccUserBlocked(User user) {
// TODO
}
void ccUserUnblocked(User user) {
// TODO
}
Widget build(BuildContext context) {
return const Placeholder();
}
}
Customization
To fit your app's design requirements, you can customize the appearance of the CometChatUsers
widget. We provide exposed methods that allow you to modify the experience and behavior according to your specific needs.
Style
You can set the CometChatUsersStyle
to the CometChatUsers
widget to customize the styling.
- Dart
CometChatUsers(
usersStyle: CometChatUsersStyle(
avatarStyle: CometChatAvatarStyle(
borderRadius: BorderRadius.circular(8),
backgroundColor: Color(0xFFFBAA75),
),
titleTextColor: Color(0xFFF76808),
separatorColor: Color(0xFFF76808),
),
)

Functionality
These are a set of small functional customizations that allow you to fine-tune the overall experience of the widget. With these, you can change text, set custom icons, and toggle the visibility of UI elements.

- Dart
CometChatUsers(
title: "Your Title",
backButton: Icon(Icons.add_alert, color: Color(0xFF6851D6)),
searchPlaceholder: "Search Users",
)
List of properties exposed by CometChatUsers
Property | Data Type | Description |
---|---|---|
usersProtocol | UsersBuilderProtocol? | Custom users request builder protocol. |
usersRequestBuilder | UsersRequestBuilder? | Custom request builder for fetching users. |
subtitleView | Widget? Function(BuildContext, User) | Widget to set subtitle for each user item. |
listItemView | Widget Function(User) | Custom view for each user item. |
usersStyle | CometChatUsersStyle | Styling options for the users list. |
scrollController | ScrollController? | Controller for scrolling the list. |
searchPlaceholder | String? | Placeholder text for the search input box. |
backButton | Widget? | Widget for the back button in the app bar. |
showBackButton | bool | Flag to show/hide the back button. |
searchBoxIcon | Widget? | Widget for the search box icon. |
hideSearch | bool | Flag to show/hide the search input box. |
selectionMode | SelectionMode? | Mode defining how users can be selected. |
onSelection | Function(List<User>?, BuildContext)? | Callback for handling user selection. |
loadingStateView | WidgetBuilder? | View displayed during loading state. |
emptyStateView | WidgetBuilder? | View displayed when the list is empty. |
errorStateView | WidgetBuilder? | View displayed when an error occurs. |
appBarOptions | List<Widget> Function(BuildContext context)? | Options available in the app bar. |
usersStatusVisibility | bool? | Hide status indicator on user avatars. |
activateSelection | ActivateSelection? | Controls whether selection is allowed. |
onError | OnError? | Callback for handling errors. |
onBack | VoidCallback? | Callback triggered when going back. |
onItemTap | Function(BuildContext context, User)? | Callback triggered when tapping a user. |
onItemLongPress | Function(BuildContext context, User)? | Callback triggered on long press of a user. |
submitIcon | Widget? | Widget for displaying the submit icon. |
hideAppbar | bool? | Flag to show/hide the app bar. |
controllerTag | String? | Identifier tag for controller management. |
height | double? | Height of the widget. |
width | double? | Width of the widget. |
stickyHeaderVisibility | bool? | Hide alphabets used to separate users. |
searchKeyword | String? | Keyword used to fetch initial user list. |
onLoad | OnLoad<User>? | Callback triggered when the list loads. |
onEmpty | OnEmpty? | Callback triggered when the list is empty. |
addOptions | List<CometChatOption>? Function(User, CometChatUsersController, BuildContext)? | Additional long-press actions for users. |
setOptions | List<CometChatOption>? Function(User, CometChatUsersController, BuildContext)? | Actions available on long-press of a user. |
titleView | Widget? Function(BuildContext, User)? | Custom title view for each user. |
leadingView | Widget? Function(User)? | Widget for leading section of each user. |
trailingView | Widget? Function(User)? | Widget for trailing section of each user. |
Advance
For advanced-level customization, you can set custom views to the widget. This lets you tailor each aspect of the widget to fit your exact needs and application aesthetics. You can create and define your own widget and then incorporate those into the widget.
setOptions
This method sets a predefined list of actions that users can perform when they long press a user in the list. These options typically include:
- Muting notifications for a specific user.
By customizing these options, developers can provide a streamlined and contextually relevant user experience
- Dart
CometChatUsers(
setOptions: (user, controller, context) {
// return options
},
)
addOptions
This method extends the existing set of actions available when users long press a user item. Unlike setOptionsDefines, which replaces the default options, addOptionsAdds allows developers to append additional actions without removing the default ones. Example use cases include:
- Adding a "Report Spam" action.
- Introducing a "Save to Notes" option.
- Integrating third-party actions such as "Share to Cloud Storage".
This method provides flexibility in modifying user interaction capabilities.
- Dart
CometChatUsers(
addOptions: (user, controller, context) {
// return options
},
)
loadingStateView
This method allows developers to set a custom loading view that is displayed when data is being fetched or loaded within the component. Instead of using a default loading spinner, a custom animation, progress bar, or branded loading screen can be displayed.
- Showing a skeleton loader for users while data loads.
- Displaying a custom progress indicator with branding.
- Providing an animated loading experience for a more engaging UI.
- Dart
CometChatUsers(
loadingStateView: (context) {
// return loading view
},
)
emptyStateView
Configures a custom view to be displayed when there are no users. This improves the user experience by providing meaningful content instead of an empty screen.
- Displaying a message like "No users yet. Start a new chat!".
- Showing an illustration or animation to make the UI visually appealing.
- Providing a button to start a new user.
- Dart
CometChatUsers(
emptyStateView: (context) {
// return empty view
},
)
errorStateView
Defines a custom error state view that appears when an issue occurs while loading users or messages. This enhances the user experience by displaying friendly error messages instead of generic system errors.
- Showing "Something went wrong. Please try again." with a retry button.
- Displaying a connection issue message if the user is offline.
- Providing troubleshooting steps for the error.
- Dart
CometChatUsers(
errorStateView: (context) {
// return error view
},
)
leadingView
This method allows developers to set a custom leading view element that appears at the beginning of each user item. Typically, this space is used for profile pictures, avatars, or user badges.
- Profile Pictures & Avatars – Display user profile images with online/offline indicators.
- Custom Icons or Badges – Show role-based badges (Admin, VIP, Verified) before the user name.
- Status Indicators – Add an active status ring or colored border based on availability.
- Dart
CometChatUsers(
leadingView: (context, user) {
// return leading view
},
)
titleView
This method customizes the title view of each user item, which typically displays the user’s name. It allows for styling modifications, additional metadata, or inline action buttons.
- Styled Usernames – Customize fonts, colors, or text sizes for the name display.
- Additional Metadata – Show extra details like username handles or job roles.
- Inline Actions – Add a follow button or verification checkmark next to the name.
- Dart
CometChatUsers(
titleView: (context, user) {
// return title view
},
)
trailingView
This method allows developers to customize the trailing (right-end) section of each user item, typically used for actions like buttons, icons, or extra information.
- Quick Actions – Add a follow/unfollow button.
- Notification Indicators – Show unread message counts or alert icons.
- Custom Info Display – Display last active time or mutual connections.
- Dart
CometChatUsers(
trailingView: (context, user) {
// return trailing view
},
)
ListItemView
With this function, you can assign a custom ListItem to the CometChatUsers
Widget.
- Dart
CometChatUsers(
listItemView: (user) {
return Placeholder();
},
)

Example
Here is the complete example for reference:
- Dart
Widget getCustomUserListItem(User user) {
return CometChatListItem(
id: user.uid,
avatarName: user.name,
avatarURL: user.avatar,
avatarHeight: 40,
avatarWidth: 40,
title: user.name,
key: UniqueKey(),
statusIndicatorStyle: CometChatStatusIndicatorStyle(
border: Border.all(
width: 2,
color: Color(0xFFFFFFFF),
),
backgroundColor: Color(0xFF56E8A7),
),
hideSeparator: true,
style: ListItemStyle(
background: user.status == CometChatUserStatus.online
? const Color(0xFFE6F4ED)
: Colors.transparent,
titleStyle: TextStyle(
overflow: TextOverflow.ellipsis,
fontSize: 16,
fontWeight: FontWeight.w500,
color: Color(0xFF141414),
),
padding: EdgeInsets.only(
left: 16,
right: 16,
top: 8,
bottom: 8,
),
),
);
}
- Dart
CometChatUsers(
listItemView: (user) {
return getCustomUserListItem(user);
},
)
SubtitleView
You can customize the subtitle view for each item to meet your specific preferences and needs.
- Dart
CometChatUsers(
subtitleView: (context, user) {
String subtitle = "";
final dateTime = user.lastActiveAt ?? DateTime.now();
subtitle = "Last Active at ${DateFormat('dd/MM/yyyy, HH:mm:ss').format(dateTime)}";
return Text(subtitle,
style: TextStyle(
color: Color(0xFF727272),
fontSize: 14,
fontWeight: FontWeight.w400,
),
);
},
)

AppBarOptions
You can set the Custom AppBarOptions to the Conversations widget.
- Dart
CometChatUsers(
appBarOptions: (context) => [
IconButton(
onPressed: () {},
icon: Icon(
Icons.add_comment_outlined,
color: Color(0xFF141414),
),
),
],
)
