Skip to main content
Version: v4

Create a Group

Create a Group

In other words, as a logged-in user, how do I create a public, private or password-protected group?

You can create a group using createGroup() method. This method takes a Group object as input.

The groupType needs to be either of the below 3 values:

1.CometChatGroupType.public (public)

2.CometChatGroupType.password (password)

3.CometChatGroupType.private (private)

String GUID = "GUID";
String groupName = "Hello Group!";
String groupType = CometChatGroupType.public;
String password = "";

Group _group = Group(guid: GUID, name: groupName, type: groupType);


await CometChat.createGroup(group: _group, onSuccess: (Group group ){
debugPrint("Group Created Successfully : $group ");
}, onError:(CometChatException e) {
debugPrint("Group Creation failed with exception: ${e.message}");
} );

The createGroup() method takes the following parameters:

ParameterDescription
groupAn instance of Group class

After the successful creation of the group, you will receive an instance of Group class which contains all the information about the particular group.

Warning

GUID can be alphanumeric with underscore and hyphen. Spaces, punctuation and other special characters are not allowed.

Group Class

FieldEditableInformation
guidNeeds to be specified at group creation. Cannot be edited laterA unique identifier for a group
nameYesName of the group
typeNoType of the group: Can be
1. Public
2. Password
3. Private
passwordNoPassword for the group in case the group is of type password.
iconYesAn URL to group icon
descriptionYesDescription about the group
ownerYesUID of the owner of the group.
metadataYesAdditional data for the group as JSON
createdAtNoThe unix timestamp of the time the group was created
updatedAtNoThe unix timestamp of the time the group was last updated
hasJoinedNoA boolean to determine if the logged in user is a member of the group.
joinedAtNoThe unix timestamp of the time the logged in user joined the group.
scopeYesScope of the logged in user. Can be:
1. Admin
2. Moderator
3. Participant
membersCountNoThe number of members in the groups
tagsYesA list of tags to identify specific groups.