updateUser static method

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

Updating a user similar to creating a user should ideally be achieved at your backend using the Restful APIs

user a user object which user needs to be updated.

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: CometChat.updateUser(User user, String apiKey, CallbackListener)

Implementation

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

    // Call native Dart user repository with apiKey
    final updatedUser = await sdk.users.updateUser(user, apiKey);

    // 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;
}