SmartPaginationCubit<T> class

Inheritance

Constructors

SmartPaginationCubit({required PaginationRequest request, required PaginationProvider<T> provider, ListBuilder<T>? listBuilder, OnInsertionCallback<T>? onInsertionCallback, VoidCallback? onClear, int maxPagesInMemory = 5, Logger? logger, RetryConfig? retryConfig, Duration? dataAge, SortOrderCollection<T>? orders, ErrorRetryStrategy errorRetryStrategy = ErrorRetryStrategy.automatic})

Properties

activeOrder SortOrder<T>?
Returns the currently active sort order.
no setter
activeOrderId String?
Returns the ID of the currently active sort order.
no setter
availableOrders List<SortOrder<T>>
Returns all available sort orders.
no setter
currentItems List<T>
Returns the current list of items, or empty list if not loaded.
no setteroverride
dataAge Duration?
Returns the configured data age duration.
no setter
didFetch bool
Whether the cubit has fetched data at least once.
getter/setter pairoverride-getter
errorRetryStrategy ErrorRetryStrategy
Strategy for handling automatic retry when an error occurs.
final
hasError bool
Returns true if the last fetch resulted in an error.
no setter
hasGridObserverController bool
Returns true if a grid observer controller is attached.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasListObserverController bool
Returns true if a list observer controller is attached.
no setter
hasObserverController bool
Returns true if any observer controller is attached.
no setter
initialRequest PaginationRequest
Initial request configuration used when the pagination starts.
final
isClosed bool
Whether the bloc is closed.
no setterinherited
isDataExpired bool
Returns true if data has expired based on the configured dataAge. If dataAge is null, data never expires. If no data has been fetched yet, returns false.
no setter
isFetching bool
Returns true if a fetch operation is currently in progress.
no setter
lastError Exception?
Returns the last error that occurred, or null if no error.
no setter
lastFetchTime DateTime?
Returns the timestamp of the last successful data fetch.
no setter
listBuilder ListBuilder<T>?
Optional hook to transform or sort items before emitting.
no setteroverride
orders SortOrderCollection<T>?
Returns the current sort order collection.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state SmartPaginationState<T>
The current state.
no setterinherited
stream Stream<SmartPaginationState<T>>
The current stream of states.
no setterinherited

Methods

addError(Object error, [StackTrace? stackTrace]) → void
Reports an error which triggers onError with an optional StackTrace.
inherited
addOrUpdateEmit(T item, {int index = 0}) → void
Adds or updates an item in the list.
override
addSortOrder(SortOrder<T> order) → void
Adds a new sort order to the collection.
animateFirstWhere(bool test(T item), {Duration duration = const Duration(milliseconds: 300), Curve curve = Curves.easeInOut, double alignment = 0.0, EdgeInsets padding = EdgeInsets.zero, BuildContext? sliverContext, bool isFixedHeight = false}) Future<bool>
Animates to the first item matching the given test function.
animateToIndex(int index, {Duration duration = const Duration(milliseconds: 300), Curve curve = Curves.easeInOut, double alignment = 0.0, EdgeInsets padding = EdgeInsets.zero, BuildContext? sliverContext, bool isFixedHeight = false}) Future<bool>
Animates to the item at the given index with smooth scrolling.
attachGridObserverController(GridObserverController controller) → void
Attaches a GridObserverController for scroll navigation.
attachListObserverController(ListObserverController controller) → void
Attaches a ListObserverController for scroll navigation.
cancelOngoingRequest() → void
Cancels any inflight work.
override
checkAndResetIfExpired() bool
Checks if data has expired and resets the cubit if so. Returns true if the data was expired and reset was triggered. This is useful when using the cubit as a global variable and re-entering a screen after some time.
clearError() → void
Clears the error state without retrying.
clearItems() → void
Clears all items from the list.
override
clearOrder() → void
Clears the active sort order (items will be in their original order).
close() Future<void>
Closes the instance. This method should be called when the instance is no longer needed. Once close is called, the instance can no longer be used.
inherited
detachAllObserverControllers() → void
Detaches all observer controllers.
detachGridObserverController() → void
Detaches the grid observer controller.
detachListObserverController() → void
Detaches the list observer controller.
dispose() → void
Disposes the cubit and its resources.
override
emit(SmartPaginationState<T> state) → void
Updates the state to the provided state. emit does nothing if the state being emitted is equal to the current state.
inherited
fetchPaginatedList({PaginationRequest? requestOverride, int? limit}) → void
Fetches the next page of the paginated list.
override
filterPaginatedList(WhereChecker<T>? searchTerm) → void
Filters the paginated list based on the provided search term.
override
insertAllEmit(List<T> items, {int index = 0}) → void
Inserts multiple items at the specified index.
override
insertEmit(T item, {int index = 0}) → void
Inserts an item at the specified index.
override
jumpFirstWhere(bool test(T item), {double alignment = 0.0, EdgeInsets padding = EdgeInsets.zero, BuildContext? sliverContext, bool isFixedHeight = false}) bool
Jumps immediately to the first item matching the given test function.
jumpToIndex(int index, {double alignment = 0.0, EdgeInsets padding = EdgeInsets.zero, BuildContext? sliverContext, bool isFixedHeight = false}) bool
Jumps immediately to the item at the given index without animation.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onChange(Change<SmartPaginationState<T>> change) → void
Called whenever a change occurs with the given change. A change occurs when a new state is emitted. onChange is called before the state of the cubit is updated. onChange is a great spot to add logging/analytics for a specific cubit.
inherited
onError(Object error, StackTrace stackTrace) → void
Called whenever an error occurs and notifies BlocObserver.onError.
inherited
refreshPaginatedList({PaginationRequest? requestOverride, int? limit}) → void
Refreshes the paginated list, starting from the beginning.
override
reload() → void
Reloads the list from the beginning (alias for refreshPaginatedList).
override
removeAtEmit(int index) → T?
Removes an item at the specified index. Returns the removed item, or null if index is out of bounds.
override
removeItemEmit(T item) bool
Removes an item from the list. Returns true if the item was found and removed.
override
removeSortOrder(String orderId) bool
Removes a sort order from the collection.
removeWhereEmit(bool test(T item)) int
Removes all items that match the predicate. Returns the number of items removed.
override
resetOrder() → void
Resets to the default sort order and re-sorts the current items.
retryAfterError() → void
Retries the last failed fetch operation.
scrollFirstWhere(bool test(T item), {bool animate = true, Duration duration = const Duration(milliseconds: 300), Curve curve = Curves.easeInOut, double alignment = 0.0, EdgeInsets padding = EdgeInsets.zero, BuildContext? sliverContext, bool isFixedHeight = false}) Future<bool>
Scrolls to the first item matching test, using animation if animate is true.
scrollToIndex(int index, {bool animate = true, Duration duration = const Duration(milliseconds: 300), Curve curve = Curves.easeInOut, double alignment = 0.0, EdgeInsets padding = EdgeInsets.zero, BuildContext? sliverContext, bool isFixedHeight = false}) Future<bool>
Scrolls to make the item at index visible, using animation if animate is true.
setActiveOrder(String orderId) bool
Sets the active sort order by ID and re-sorts the current items.
setItems(List<T> items) → void
Sets the list to a completely new set of items.
override
setOrders(SortOrderCollection<T>? orders) → void
Sets the sort order collection.
sortBy(ItemComparator<T> comparator) → void
Sorts items using a one-time comparator without changing the active order.
toString() String
A string representation of this object.
inherited
updateItemEmit(bool matcher(T item), T updater(T item)) bool
Updates an item in the list using a matcher and updater function. Returns true if an item was found and updated.
override
updateWhereEmit(bool matcher(T item), T updater(T item)) int
Updates all items that match the predicate. Returns the number of items updated.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited