loadMore method
Load more data from the server using nextPageKey.
Implementation
@override
Future<void> loadMore(String nextPageKey) async {
final generation = loadGeneration;
final previousValue = value.asSuccess;
try {
final response = await client.search(
_activeFilter,
sort: _activeSort,
query: _activeSearchQuery,
messageFilters: _activeMessageFilter,
paginationParams: PaginationParams(limit: limit, next: nextPageKey),
);
// Drop the page if a newer search or clearResults() superseded it, so a
// stale page cannot repopulate the results.
if (isStale(generation)) return;
final results = response.results;
final previousItems = previousValue.items;
final newItems = previousItems + results;
final next = response.next;
final nextKey = next != null && next.isNotEmpty ? next : null;
value = PagedValue(
items: newItems,
nextPageKey: nextKey,
);
} on StreamChatError catch (error) {
if (isStale(generation)) return;
value = previousValue.copyWith(error: error);
} catch (error) {
if (isStale(generation)) return;
final chatError = StreamChatError(error.toString());
value = previousValue.copyWith(error: chatError);
}
}