fetchNext method

Future<List<User>> fetchNext({
  1. required dynamic onSuccess(
    1. List<User> userList
    )?,
  2. required dynamic onError(
    1. CometChatException excep
    )?,
})

Implementation

Future<List<User>> fetchNext({required Function(List<User> userList)? onSuccess, required Function(CometChatException excep)? onError}) async {
  try {
    final result = await channel.invokeMethod('fetchUsers', {
      'searchTerm': this.searchKeyword,
      'limit': this.limit,
      'hidebloackedUsers': this.hideBlockedUsers,
      'userRoles': this.roles,
      'friendsOnly': this.friendsOnly,
      'tags': this.tags,
      'withTags': this.withTags,
      'userStatus': this.userStatus,
      'uids': this.uids,
      'key': this.key
    });
    final List<User> res = [];
    if (result != null) {
      key = result["key"];
      if (result["list"] != null) {
        for (var _obj in result["list"]) {
          try {
            res.add(User.fromMap(_obj));
          } catch (e) {
            if(onError != null) onError(CometChatException(ErrorCode.errorUnhandledException, e.toString() , e.toString()));
            return [];
          }
        }
      }
    }
    debugPrint("key is $key");
    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 [];
}