> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Retrieve Group Members

> Fetch CometChat group members in Flutter apps with group GUID, pagination limits, search keywords, and member scopes.

## Retrieve the List of Group Members

In order to fetch the list of groups members for a group, you can use the `GroupMembersRequest` class. To use this class i.e to create an object of the `GroupMembersRequest` class, you need to use the `GroupMembersRequestBuilder` class. The `GroupMembersRequestBuilder` class allows you to set the parameters based on which the groups are to be fetched.

The `GroupMembersRequestBuilder` class allows you to set the below parameters:

The `GUID` of the group for which the members are to be fetched must be specified in the constructor of the `GroupMembersRequestBuilder` class.

### Set Limit

This method sets the limit i.e. the number of members that should be fetched in a single iteration.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    String GUID = "GUID";
      GroupMembersRequest  groupMembersRequest = (GroupMembersRequestBuilder(GUID)
      ..limit = 20
      ).build();
    ```
  </Tab>
</Tabs>

### Set Search Keyword

This method allows you to set the search string based on which the group members are to be fetched.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    String GUID = "GUID";
    GroupMembersRequest  groupMembersRequest = (GroupMembersRequestBuilder(GUID)
      ..limit = 20
      ..searchKeyword = "abc"
      ).build();
    ```
  </Tab>
</Tabs>

### Set Scopes

This method allows you to fetch group members based on the specified scopes.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    List<String> scopes =[];
    scopes.add("admin");
    scopes.add("moderator");
    String GUID = "GUID";
    GroupMembersRequest  groupMembersRequest = (GroupMembersRequestBuilder(GUID)
      ..limit = 20
      ..scopes = scopes
      ).build();
    ```
  </Tab>
</Tabs>

### Set Status

This method allows you to filter group members based on their online/offline status.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    String GUID = "GUID";
    GroupMembersRequest groupMembersRequest = (GroupMembersRequestBuilder(GUID)
      ..limit = 20
      ..status = CometChatUserStatus.online  // or CometChatUserStatus.offline
      ).build();
    ```
  </Tab>
</Tabs>

The `status` parameter can contain one of the below two values:

* `CometChatUserStatus.online` - will return only online group members.
* `CometChatUserStatus.offline` - will return only offline group members.

If this parameter is not set, all group members will be returned regardless of their status.

Finally, once all the parameters are set to the builder class, you need to call the `build()` method to get the object of the `GroupMembersRequest` class.

Once you have the object of the `GroupMembersRequest` class, you need to call the `fetchNext()` method. Calling this method will return a list of `GroupMember` objects containing N number of members depending on the limit set.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    String GUID = "GUID";
    GroupMembersRequest  groupMembersRequest = (GroupMembersRequestBuilder(GUID)
      ..limit = 20
      ).build();

    groupMembersRequest.fetchNext(onSuccess: (List<GroupMember> groupMemberList){
        debugPrint("Group Members fetched Successfully : $groupMemberList ");  
      }, onError: (CometChatException e) {
        debugPrint("Delete Group failed with exception: ${e.message}");
      });
    ```
  </Tab>
</Tabs>
