updateCurrentUserDetails static method

Future<User?> updateCurrentUserDetails(
  1. User user, {
  2. required dynamic onSuccess(
    1. User retUser
    )?,
  3. required dynamic onError(
    1. CometChatException excep
    )?,
})

Updating a logged-in user is similar to updating a user

method could throw PlatformException with error codes specifying the cause

Implementation

static Future<User?> updateCurrentUserDetails(User user, {required Function(User retUser)? onSuccess, required Function(CometChatException excep)? onError}) async {
  try {
    final result = await channel.invokeMethod('updateCurrentUserDetails', {
      'name': user.name,
      'link': user.link,
      'tags': user.tags,
      'avatar': user.avatar,
      'statusMessage': user.statusMessage,
      'metadata': user.metadata == null ? null : json.encode(user.metadata),
      'role': user.role,
      'lastActiveAt': user.lastActiveAt == null
          ? null
          : user.lastActiveAt!.millisecondsSinceEpoch,
      'hasBlockedMe': user.hasBlockedMe,
      'blockedByMe': user.blockedByMe,
      'status': user.status
    });
    final User res = User.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;
}