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})

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
hashCode int
The hash code for this object.
no setterinherited
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
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.
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.
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
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
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.
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