fetchNext method

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

Returns list of Group object fetched after putting the filters.

limit limit the number of groups retreaved.

searchTerm term for group retreavel.

method could throw PlatformException with error codes specifying the cause

See also Android Documentation IOS Documentation

Implementation

Future<List<Group>> fetchNext({required Function(List<Group> groupList)? onSuccess, required Function(CometChatException excep)? onError}) async {
  try {
    final result = await channel.invokeMethod('fetchNextGroups', {
      'searchTerm': this.searchKeyword,
      'limit': this.limit,
      'joinedOnly': this.joinedOnly,
      'tags': this.tags,
      'withTags': this.withTags,
      'key': this.key
    });
    final List<Group> res = [];
    if (result != null) {
      key = result["key"];
      if (result["list"] != null) {
        for (var _obj in result["list"]) {
          try {
            res.add(Group.fromMap(_obj));
          } catch (e) {
            if(onError != null) onError(CometChatException(ErrorCode.errorUnhandledException, e.toString() , e.toString()));
            return [];
          }
        }
      }
    }
    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 [];
}