loadPage method
Load a specific page
Implementation
Future<void> loadPage(int page) async {
if (_state.value.isLoading) return;
Transaction.run(() {
_state.value = _state.value.copyWith(isLoading: true, error: null);
});
try {
final items = await _loadPage(page, _pageSize);
final hasMore = items.length >= _pageSize;
Transaction.run(() {
if (page == 0) {
// First page - replace items
_state.value = _state.value.copyWith(
items: items,
currentPage: page,
hasMore: hasMore,
isLoading: false,
error: null,
);
} else {
// Subsequent pages - append items
_state.value = _state.value.copyWith(
items: [..._state.value.items, ...items],
currentPage: page,
hasMore: hasMore,
isLoading: false,
error: null,
);
}
});
Logger.debug('Loaded page $page with ${items.length} items');
} catch (e) {
Transaction.run(() {
_state.value = _state.value.copyWith(
isLoading: false,
error: e,
);
});
Logger.error('Error loading page $page', e);
rethrow;
}
}