updateGroup static method

Future<Group?> updateGroup({
  1. required Group group,
  2. required dynamic onSuccess(
    1. Group group
    )?,
  3. required dynamic onError(
    1. CometChatException excep
    )?,
})

update the group details

guid an instance of class Group

method could throw PlatformException with error codes specifying the cause

Implementation

static Future<Group?> updateGroup({required Group group, required Function(Group group)? onSuccess, required Function(CometChatException excep)? onError}) async {
  try {
    final result = await channel.invokeMethod('updateGroup', {
      '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 Group res = Group.fromMap(result);
    if(onSuccess != null) onSuccess(res);
    return res;
  } on PlatformException catch (platformException) {
    if(onError != null) onError(CometChatException(platformException.code, platformException.details, platformException.message));
  } catch (e) {
    debugPrint("Error: $e");
    if(onError != null) onError(CometChatException(ErrorCode.errorUnhandledException, e.toString() , e.toString()));
  }
  return null;
}