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

Migration Note: Migrated from platform channels to native Dart implementation. Behavior and signature remain identical for backward compatibility.

Android Reference: UsersRequest.updateCurrentUserDetails(User user)

Implementation

static Future<User?> updateCurrentUserDetails(User user,
    {required Function(User retUser)? onSuccess,
    required Function(CometChatException excep)? onError}) async {
  try {
    // Get SDK instance
    final sdk = SdkRegistry.getInstance();

    // Call native Dart user repository
    final updatedUser = await sdk.users.updateMyDetails(user);

    // Call success callback
    if (onSuccess != null) onSuccess(updatedUser);
    return updatedUser;
  } 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) {
    _errorCallbackHandler(null, null, e, onError);
  }
  return null;
}