createGroup static method

Future<Group?> createGroup({
  1. required Group group,
  2. required dynamic onSuccess(
    1. Group group
    )?,
  3. required dynamic onError(
    1. 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

Implementation

static Future<Group?> createGroup(
    {required Group group,
    required Function(Group group)? onSuccess,
    required Function(CometChatException excep)? onError}) async {
  try {
    final result = await channel.invokeMethod('createGroup', {
      'guid': group.guid,
      'name': group.name,
      'icon': group.icon,
      'description': group.description,
      'membersCount': group.membersCount,
      'metadata': group.metadata == null || group.metadata!.isEmpty
          ? null
          : json.encode(group.metadata),
      'joinedAt': group.joinedAt == null
          ? null
          : group.joinedAt!.millisecondsSinceEpoch,
      'hasJoined': group.hasJoined,
      'createdAt': group.createdAt == null
          ? null
          : group.createdAt!.millisecondsSinceEpoch,
      'owner': group.owner,
      'updatedAt': group.updatedAt == null
          ? null
          : group.updatedAt!.millisecondsSinceEpoch,
      'tags': group.tags,
      'type': group.type,
      'scope': group.scope,
      'password': group.password,
    });
    final res = Group.fromMap(result);
    if (onSuccess != null) onSuccess(res);
    return res;
  } on PlatformException catch (p) {
    _errorCallbackHandler(null, p, null, onError);
  } catch (e) {
    _errorCallbackHandler(null, null, e, onError);
  }
  return null;
}