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

# Join A Group

> Join CometChat public and password-protected groups in Flutter apps using group GUIDs and password validation.

<Accordion title="AI Integration Quick Reference">
  | Field | Value |
  | - | - |
  | Package | `cometchat_sdk` |
  | Import | `import 'package:cometchat_sdk/cometchat_sdk.dart';` |
  | Purpose | Join CometChat public and password-protected groups in Flutter apps using group GUIDs and password validation. |
  | Key methods | `addGroupListener()` · `joinGroup()` |
  | Key classes | `Group` · `Action` · `CometChatException` · `User` · `CometChatGroupType` |
  | Listener callbacks | `onGroupMemberJoined()` |
  | Prerequisites | SDK initialised via [`CometChat.init()`](/sdk/flutter/setup) and a logged-in user via [`CometChat.login()`](/sdk/flutter/authentication-overview). |
  | Constraints | `onSuccess` and `onError` are **both required** — omitting either is a compile error, and awaiting the call alone gives you nothing to act on. Put the success path inside `onSuccess`. |
  | Related | [Create A Group](/sdk/flutter/create-group) · [Leave A Group](/sdk/flutter/leave-group) |
  | Full reference | [`Group`](/sdk/reference/entities#group) · [`Action`](/sdk/reference/messages#action) · [`CometChatException`](/sdk/reference/auxiliary#cometchatexception) · [`User`](/sdk/reference/entities#user) |
</Accordion>

## Join a Group

In order to start participating in group conversations, you will have to join a group. You can do so using the `joinGroup()` method.

<Tabs>
  <Tab title="Dart">
    ```dart theme={null}
    String GUID = "GUID";
    String groupType = CometChatGroupType.public;
    String password = "";

    CometChat.joinGroup(GUID, groupType, password: password,
                      onSuccess: (Group group) {
                        debugPrint("Group Joined Successfully : $group ");
                      }, onError: (CometChatException e) {
                        debugPrint("Group Joining failed with exception: ${e.message}");
      });
    ```
  </Tab>
</Tabs>

The `joinGroup()` method takes the below parameters

| Parameter | Description |
| - | - |
| `GUID` | The GUID of the group you would like to join |
| `groupType` | Type of the group. CometChat provides 3 types of groups viz. 1.CometChatGroupType.*public* (public). 2.CometChatGroupType.*password* (password) 3.CometChatGroupType.*private* (private) |
| `password` | Password is mandatory in case of a password protected group. |

Once you have joined a group successfully, you can send and receive messages in that group.

CometChat keeps a track of the groups joined and you do not need to join the group everytime you want to communicate in the group.

You can identify if a group is joined using the `hasJoined` parameter in the `Group` object.

## Real-time Group Member Joined Events

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

If a user joins any group, the members of the group receive a real-time event in the `onGroupMemberJoined()` 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 onGroupMemberJoined(Action action, User joinedUser, Group joinedGroup) {
      debugPrint("onGroupMemberJoined");
    }
    ```
  </Tab>
</Tabs>

## Missed Group Member Joined Events

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

When you retrieve the list of previous messages if a member has joined any group that the logged-in user is a member of, the list of messages will contain an `Action` message. An `Action` message is a sub-class of `BaseMessage` class.

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

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


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.