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

Implementation

static Future<User?> updateUser(User user, String apiKey,
    {required Function(User retUser)? onSuccess,
    required Function(CometChatException excep)? onError}) async {
  try {
    final result = await channel.invokeMethod('updateUser', {
      'uid': user.uid,
      'name': user.name,
      'link': user.link,
      'tags': user.tags,
      'avatar': user.avatar,
      'statusMessage': user.statusMessage,
      'metadata': user.metadata == null ? null : json.encode(user.metadata),
      'apiKey': apiKey,
      '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 user;
  } on PlatformException catch (p) {
    _errorCallbackHandler(null, p, null, onError);
  } catch (e) {
    _errorCallbackHandler(null, null, e, onError);
  }
  return null;
}