createGroup static method
Future<Group?>
createGroup({
- required Group group,
- required dynamic onSuccess(
- Group group
- required dynamic onError(
- CometChatException excep
Returns a Group object after creating in CometChat API.
guid A unique identifier for a group. Can be alphanumeric with underscore and hyphens only.
groupName name of group.
groupType needs to be either of the below 3 values public, private, password.
password Mandatory in case group is password only.
method could throw PlatformException with error codes specifying the cause Creates a new group.
Migration Note: Migrated from platform channels to native Dart. Behavior and signature remain identical.
Android Reference: GroupsRequest.createGroup(Group group)
Implementation
static Future<Group?> createGroup(
{required Group group,
required Function(Group group)? onSuccess,
required Function(CometChatException excep)? onError}) async {
try {
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Call repository
final createdGroup = await sdk.groups.createGroup(group);
// Call success callback
if (onSuccess != null) onSuccess(createdGroup);
return createdGroup;
} on SdkException catch (sdkEx) {
// Convert SdkException to CometChatException
final cometChatEx = CometChatException(
sdkEx.code,
sdkEx.details ?? sdkEx.message,
sdkEx.message,
);
_errorCallbackHandler(cometChatEx, null, null, onError);
} catch (e) {
// Handle unexpected errors
_errorCallbackHandler(null, null, e, onError);
}
return null;
}