loadMore method
Load more data from the server using nextPageKey
.
Implementation
@override
Future<void> loadMore(String nextPageKey) async {
final previousValue = value.asSuccess;
try {
final response = await client.search(
_activeFilter,
sort: _activeSort,
query: _activeSearchQuery,
messageFilters: _activeMessageFilter,
paginationParams: PaginationParams(limit: limit, next: nextPageKey),
);
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) {
value = previousValue.copyWith(error: error);
} catch (error) {
final chatError = StreamChatError(error.toString());
value = previousValue.copyWith(error: chatError);
}
}