loadMore method
Load more data from the server using nextPageKey
.
Implementation
@override
Future<void> loadMore(int page) async {
final previousValue = value.asSuccess;
try {
final assets = await _getRecentAssetPathList();
if (assets == null) {
const chatError = StreamChatError('No media found');
value = previousValue.copyWith(error: chatError);
return;
}
final mediaList = await assets.getAssetListPaged(
page: page,
size: limit,
);
final previousItems = previousValue.items;
final newItems = previousItems + mediaList;
final nextKey = mediaList.length < limit ? null : page + 1;
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);
}
}