updateUser static method
Future<User?>
updateUser(
- User user,
- String apiKey, {
- required dynamic onSuccess(
- User retUser
- required dynamic onError(
- 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;
}