loadNext method Null safety

  1. @override
Future<List<User>> loadNext()
override

Load next items asynchronously

Implementation

@override
Future<List<User>> loadNext() async {
  if (loading) throw QueryInProgressError();
  if (!hasNext) return [];

  final sdk = SendbirdSdk().getInternal();

  switch (queryType) {
    case UserListQueryType.banned:
    case UserListQueryType.muted:
      if (channelType == null || channelUrl == null) {
        throw InvalidParameterError();
      }
      break;
    case UserListQueryType.participants:
      if (channelUrl == null) throw InvalidParameterError();
      break;
    default:
      break;
  }

  loading = true;

  UserListQueryResponse res;
  switch (queryType) {
    case UserListQueryType.filtered:
      res = await sdk.api.getUsers(
        token: token,
        limit: limit,
        userIds: userIds,
      );
      break;
    case UserListQueryType.banned:
      res = await sdk.api.getBannedUsers(
        type: channelType!,
        channelUrl: channelUrl!,
        token: token,
        limit: limit,
      );
      break;
    case UserListQueryType.blocked:
      res = await sdk.api.getBlockedUsers(
        token: token,
        limit: limit,
      );
      break;
    case UserListQueryType.muted:
      res = await sdk.api.getMutedUsers(
        type: channelType!,
        channelUrl: channelUrl!,
        token: token,
        limit: limit,
      );
      break;
    case UserListQueryType.participants:
      res = await sdk.api.getOpenChannelParticipants(
        channelUrl: channelUrl,
        token: token,
        limit: limit,
      );
      break;
  }

  loading = false;
  token = res.next;
  hasNext = res.next != '';
  return res.users;
}