loadMore method
Load more data from the server using nextPageKey
.
Implementation
@override
Future<void> loadMore(int nextPageKey) async {
final previousValue = value.asSuccess;
try {
await for (final channels in client.queryChannels(
filter: filter,
channelStateSort: channelStateSort,
memberLimit: memberLimit,
messageLimit: messageLimit,
presence: presence,
paginationParams: PaginationParams(limit: limit, offset: nextPageKey),
)) {
final previousItems = previousValue.items;
final newItems = previousItems + channels;
final nextKey = channels.length < limit ? null : newItems.length;
value = PagedValue(
items: newItems,
nextPageKey: nextKey,
);
}
} on StreamChatError catch (error) {
value = previousValue.copyWith(error: error);
} catch (error) {
final chatError = StreamChatError(error.toString());
value = previousValue.copyWith(error: chatError);
}
}