doInitialLoad method

  1. @override
Future<void> doInitialLoad()
override

Load initial data from the server.

Implementation

@override
Future<void> doInitialLoad() async {
  final limit = min(
    this.limit * defaultInitialPagedLimitMultiplier,
    _kDefaultBackendPaginationLimit,
  );
  try {
    await for (final channels in client.queryChannels(
      filter: filter,
      channelStateSort: channelStateSort,
      // ignore: deprecated_member_use, deprecated_member_use_from_same_package
      sort: sort,
      memberLimit: memberLimit,
      messageLimit: messageLimit,
      presence: presence,
      paginationParams: PaginationParams(limit: limit),
    )) {
      final nextKey = channels.length < limit ? null : channels.length;
      value = PagedValue(
        items: channels,
        nextPageKey: nextKey,
      );
    }
    // start listening to events
    _subscribeToChannelListEvents();
  } on StreamChatError catch (error) {
    value = PagedValue.error(error);
  } catch (error) {
    final chatError = StreamChatError(error.toString());
    value = PagedValue.error(chatError);
  }
}