> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Users

## Overview

The `CometChatUsers` is a [Widget](/ui-kit/flutter/components-overview#components), 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.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/skyYyiTRS367pk0g/images/90576bd9-users-5145e7bd94f9ca2761fe942ec7a13907.png?fit=max&auto=format&n=skyYyiTRS367pk0g&q=85&s=3492ae3692430e4c0da1d3f0011a32d0" width="2560" height="1600" data-path="images/90576bd9-users-5145e7bd94f9ca2761fe942ec7a13907.png" />
</Frame>

The `CometChatUsers` widget is composed of the following Base Widgets:

| Widgets                               | Description                                                                                                          |
| ------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| [ListBase](/ui-kit/flutter/list-base) | a reusable container widget having title, search box, customisable background and a List View                        |
| [ListItem](/ui-kit/flutter/list-item) | 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`

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    Navigator.push(context, MaterialPageRoute(builder: (context) => const CometChatUsers()));
    ```
  </Tab>
</Tabs>

##### 2. Embedding `CometChatUsers` as a Widget in the build Method

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';
    import 'package:flutter/material.dart';

    class Users extends StatefulWidget {
      const Users({super.key});

      @override
      State<Users> createState() => _UsersState();
    }

    class _UsersState extends State<Users> {

      @override
      Widget build(BuildContext context) {
        return const Scaffold(
            body: SafeArea(
                child: CometChatUsers()
            )
        );
      }
    }
    ```
  </Tab>
</Tabs>

***

### Actions

[Actions](/ui-kit/flutter/components-overview#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.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
      selectionMode: SelectionMode.multiple,
      activateSelection: ActivateSelection.onClick,
      onSelection: (list, context) {
        //TODO: This action will trigger the end of selection.
      },
    )
    ```
  </Tab>
</Tabs>

***

##### 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.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
      onItemTap: (context, user) {
        // TODO("Not yet implemented")
      },
    )
    ```
  </Tab>
</Tabs>

***

##### 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.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
      onBack: () {
        // TODO("Not yet implemented")
      },
    )
    ```
  </Tab>
</Tabs>

***

##### onError

This method `onError`, allows users to override error handling within `CometChatUsers`, providing greater control over error responses and actions.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
      onError: (e) {
        // TODO("Not yet implemented")
      },
    )
    ```
  </Tab>
</Tabs>

***

##### onItemLongPress

This method `onItemLongPress`, empowers users to customize long-click actions within `CometChatUsers`, offering enhanced functionality and interaction possibilities.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
      onItemLongPress: (context, user) {
        // TODO("Not yet implemented")
      },
    )
    ```
  </Tab>
</Tabs>

***

##### onLoad

Invoked when the list is successfully fetched and loaded, helping track component readiness.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
         onLoad: (list) {
              // print("User List: $list");
            },
    )
    ```
  </Tab>
</Tabs>

***

##### onEmpty

Called when the list is empty, enabling custom handling such as showing a placeholder message.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
          onEmpty: () {
              // print("User List is empty");
            },
    )
    ```
  </Tab>
</Tabs>

***

### 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](/sdk/flutter/retrieve-users) 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](/sdk/flutter/retrieve-users)

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
        usersRequestBuilder: UsersRequestBuilder()
            ..limit = 10
    )
    ```
  </Tab>
</Tabs>

***

### Events

[Events](/ui-kit/flutter/components-overview#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 |

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart';
    import 'package:flutter/material.dart';

    class YourScreen extends StatefulWidget {
      const YourScreen({super.key});

      @override
      State<YourScreen> createState() => _YourScreenState();
    }

    class _YourScreenState extends State<YourScreen> with CometChatUserEventListener {

      @override
      void initState() {
        super.initState();
        CometChatUserEvents.addUsersListener("listenerId", this);
      }

      @override
      void dispose(){
        super.dispose();
        CometChatUserEvents.removeUsersListener("listenerId");
      }

      @override
      void ccUserBlocked(User user) {
        // TODO
      }

      @override
      void ccUserUnblocked(User user) {
        // TODO
      }

      @override
      Widget build(BuildContext context) {
        return const Placeholder();
      }

    }
    ```
  </Tab>
</Tabs>

***

## 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.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
      usersStyle: CometChatUsersStyle(
        avatarStyle: CometChatAvatarStyle(
        borderRadius: BorderRadius.circular(8),
        backgroundColor: Color(0xFFFBAA75),
        ),
        titleTextColor: Color(0xFFF76808),
        separatorColor: Color(0xFFF76808),
      ),
    )
    ```
  </Tab>
</Tabs>

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/yDKVamMkf61gj3YR/images/e52ab7f6-users_styling-eb50f461911a21f33a5e96e90751deda.png?fit=max&auto=format&n=yDKVamMkf61gj3YR&q=85&s=72eec3860bf420d0d101ad631c433d12" width="2560" height="1600" data-path="images/e52ab7f6-users_styling-eb50f461911a21f33a5e96e90751deda.png" />
</Frame>

***

### 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.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/skyYyiTRS367pk0g/images/90576bd9-users-5145e7bd94f9ca2761fe942ec7a13907.png?fit=max&auto=format&n=skyYyiTRS367pk0g&q=85&s=3492ae3692430e4c0da1d3f0011a32d0" width="2560" height="1600" data-path="images/90576bd9-users-5145e7bd94f9ca2761fe942ec7a13907.png" />
</Frame>

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
      title: "Your Title",
      backButton: Icon(Icons.add_alert, color: Color(0xFF6851D6)),
      searchPlaceholder: "Search Users",
    )
    ```
  </Tab>
</Tabs>

## 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

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
      setOptions: (user, controller, context) {
        // return options
      },
    )
    ```
  </Tab>
</Tabs>

***

#### 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.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
      addOptions: (user, controller, context) {
        // return options
      },
    )
    ```
  </Tab>
</Tabs>

***

#### 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.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
        loadingStateView: (context) {
          // return loading view
      },
    )
    ```
  </Tab>
</Tabs>

***

#### 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.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
        emptyStateView: (context) {
          // return empty view
      },
    )
    ```
  </Tab>
</Tabs>

***

#### 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.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
        errorStateView: (context) {
          // return error view
      },
    )
    ```
  </Tab>
</Tabs>

***

#### 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.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
        leadingView: (context, user) {
           // return leading view
        },
    )
    ```
  </Tab>
</Tabs>

***

#### 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.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
        titleView: (context, user) {
          // return title view
        },
    )
    ```
  </Tab>
</Tabs>

***

#### 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.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
        trailingView: (context, user) {
          // return trailing view
        },
    )
    ```
  </Tab>
</Tabs>

***

#### ListItemView

With this function, you can assign a custom ListItem to the `CometChatUsers` Widget.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
      listItemView: (user) {
        return Placeholder();
      },
    )
    ```
  </Tab>
</Tabs>

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/KtMgt-R-YUJVVdNY/images/de656dc8-users_list_item_view-e66a444aac7edcb18dec787a42b646c3.png?fit=max&auto=format&n=KtMgt-R-YUJVVdNY&q=85&s=58c7bf8700e39e6d193bd9b307b3dca8" width="1280" height="800" data-path="images/de656dc8-users_list_item_view-e66a444aac7edcb18dec787a42b646c3.png" />
</Frame>

**Example**

Here is the complete example for reference:

<Tabs>
  <Tab title="Dart">
    ```dart custom_list_item.dart theme={null}
     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,
            ),
          ),
        );
      }
    ```
  </Tab>
</Tabs>

<Tabs>
  <Tab title="Dart">
    ```dart main.dart theme={null}
    CometChatUsers(
      listItemView: (user) {
          return getCustomUserListItem(user);
      },
    )
    ```
  </Tab>
</Tabs>

***

#### SubtitleView

You can customize the subtitle view for each item to meet your specific preferences and needs.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    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,
                    ),
                  );
        },
    )
    ```
  </Tab>
</Tabs>

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/Lc9mXSk8oVxt1t7p/images/6e16192f-users_subtitle_view-51f448114408521010b6feb4a5bba41d.png?fit=max&auto=format&n=Lc9mXSk8oVxt1t7p&q=85&s=e30d88bc7f67728c86d1e4a02f1a293e" width="1280" height="800" data-path="images/6e16192f-users_subtitle_view-51f448114408521010b6feb4a5bba41d.png" />
</Frame>

***

#### AppBarOptions

You can set the Custom AppBarOptions to the Conversations widget.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    CometChatUsers(
      appBarOptions: (context) => [
                  IconButton(
                    onPressed: () {},
                    icon: Icon(
                      Icons.add_comment_outlined,
                      color: Color(0xFF141414),
                    ),
                  ),
                ],
    )
    ```
  </Tab>
</Tabs>

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b-feature-react-native-sdk-quotedmessage-a/Zp9d87qbHHZCI7d4/images/d305b006-users_menu-5b7eb7088d966ada9e751e591dbee212.png?fit=max&auto=format&n=Zp9d87qbHHZCI7d4&q=85&s=19ea8fda25668e1ddec5aea40ce2a261" width="1280" height="800" data-path="images/d305b006-users_menu-5b7eb7088d966ada9e751e591dbee212.png" />
</Frame>

***
