> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-angular-v5-docs-update.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Leave A Group

> Learn how to leave a group and receive real-time events when members leave using the CometChat Flutter SDK.

<Accordion title="AI Integration Quick Reference">
  ```dart theme={null}
  // Leave a group
  CometChat.leaveGroup("GROUP_GUID",
    onSuccess: (String message) => debugPrint("Left group: $message"),
    onError: (CometChatException e) => debugPrint("Error: ${e.message}"),
  );

  // Listen for group member left events
  CometChat.addGroupListener("listener_id", GroupListener(
    onGroupMemberLeft: (Action action, User leftUser, Group leftGroup) {
      debugPrint("${leftUser.name} left ${leftGroup.name}");
    },
  ));
  ```
</Accordion>

Leave a group to stop receiving messages and updates from it. Once you leave, you'll need to rejoin to participate again.

<Note>
  Group owners cannot leave without first transferring ownership to another member. See [Transfer Group Ownership](/sdk/flutter/transfer-group-ownership).
</Note>

## Leave a Group

Use `leaveGroup()` to leave a group.

<Note>
  **Available via:** SDK | [REST API](https://api-explorer.cometchat.com) | [UI Kits](/ui-kit/flutter/overview)
</Note>

### Parameters

| Parameter   | Type                                  | Description                                   |
| ----------- | ------------------------------------- | --------------------------------------------- |
| `guid`      | `String`                              | The GUID of the group you would like to leave |
| `onSuccess` | `Function(String returnResponse)?`    | Callback triggered on successful leave        |
| `onError`   | `Function(CometChatException excep)?` | Callback triggered on error                   |

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    String GUID = "GUID";

    CometChat.leaveGroup(GUID, onSuccess: ( String message) {
          debugPrint("Group Left  Successfully : $message");
        },onError: (CometChatException e) {
          debugPrint("Group Left failed  : ${e.message}");
        }); 
    ```
  </Tab>
</Tabs>

<Accordion title="Response">
  **On Success** — A `String` message confirming the operation:

  <span id="leave-group-message" style={{scrollMarginTop: '100px'}} />

  | Parameter | Type   | Description                  | Sample Value                           |
  | --------- | ------ | ---------------------------- | -------------------------------------- |
  | `message` | string | Success confirmation message | `"cometchat-guid-1 left successfully"` |
</Accordion>

<Accordion title="Error">
  <span id="leave-group-error" style={{scrollMarginTop: '100px'}} />

  | Parameter | Type   | Description                  | Sample Value                                           |
  | --------- | ------ | ---------------------------- | ------------------------------------------------------ |
  | `code`    | string | Error code identifier        | `"ERR_NOT_A_MEMBER"`                                   |
  | `message` | string | Human-readable error message | `"The user is not a member of this group."`            |
  | `details` | string | Additional technical details | `"Cannot leave a group that you are not a member of."` |
</Accordion>

Once a group is left, the user will no longer receive any updates or messages pertaining to the group.

## Real-time Group Member Left Events

*In other words, as a member of a group, how do I know if someone has left it when my app is running?*

If a user leaves a group, the members of the group receive a real-time event in the `onGroupMemberLeft()` method of the `GroupListener` class.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    class Class_Name  with GroupListener {

    //CometChat.addGroupListener("group_Listener_id", this);
    @override
    void onGroupMemberLeft(Action action, User leftUser, Group leftGroup) {
      print("onGroupMemberLeft ");

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

<Warning>
  Always remove group listeners when they're no longer needed (e.g., in `dispose()`). Failing to remove listeners can cause memory leaks and duplicate event handling.

  ```dart theme={null}
  CometChat.removeGroupListener("group_Listener_id");
  ```
</Warning>

## Missed Group Member Left Events

*In other words, as a member of a group, how do I know if someone has left it when my app is not running?*

When you retrieve the list of previous messages if a member has left any group that the logged-in user is a member of, the list of messages will contain an [`Action`](/sdk/reference/messages#action) message. An `Action` message is a sub-class of [`BaseMessage`](/sdk/reference/messages#basemessage) class.

For the group member left event, in the `Action` object received, the following fields can help you get the relevant information-

1. `action` - `left`
2. `actionBy` - User object containing the details of the user who left the group
3. `actionFor` - Group object containing the details of the group the user has left

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Join a Group" icon="right-to-bracket" href="/sdk/flutter/join-group">
    Join public or password-protected groups
  </Card>

  <Card title="Delete a Group" icon="trash" href="/sdk/flutter/delete-group">
    Permanently delete a group (admin only)
  </Card>

  <Card title="Kick & Ban Members" icon="user-slash" href="/sdk/flutter/group-kick-ban-members">
    Remove or ban members from a group
  </Card>

  <Card title="Retrieve Groups" icon="list" href="/sdk/flutter/retrieve-groups">
    Fetch and filter the list of groups
  </Card>
</CardGroup>
