ListBase<T> mixin
A generic mixin providing list management operations for BLoC classes.
This mixin can be mixed into any BLoC to provide reusable list operations with customizable hooks that can be overridden for custom behavior.
Example usage:
class MyBloc extends Bloc<MyEvent, MyState> with ListBase<MyItem> {
@override
void onItemAdded(MyItem item, List<MyItem> updatedList) {
// Custom logic when item is added
emit(MyState(items: updatedList));
}
}
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEmpty → bool
-
Returns true if the list is empty
no setter
- isNotEmpty → bool
-
Returns true if the list is not empty
no setter
- itemCount → int
-
Returns the number of items in the list
no setter
-
items
→ List<
T> -
Returns an unmodifiable view of the current items
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addAllItems(
List< T> itemsToAdd) → void - Adds multiple items to the end of the list. Calls onItemAdded hook for each item.
-
addAllItemsAtStart(
List< T> itemsToAdd) → void - Adds items at the beginning of the list.
-
addItem(
T item) → void - Adds an item to the end of the list. Calls onItemAdded hook after adding.
-
addUniqueItem(
T item) → bool - Adds an item only if it doesn't already exist in the list. Returns true if item was added.
-
clearItems(
) → void - Clears all items from the list.
-
containsItem(
T item) → bool - Checks if the list contains a specified item.
-
filterItems(
bool predicate(T item)) → void - Filters items based on a predicate. Removes items that don't match the predicate.
-
findFirst(
bool predicate(T item)) → T? - Finds the first item matching the predicate. Returns null if no item matches.
-
findIndex(
bool predicate(T item)) → int - Finds the index of the first item matching the predicate. Returns -1 if no item matches.
-
getItemAt(
int index) → T? - Retrieves an item at a specific index safely. Returns null if index is out of bounds.
-
insertItemAt(
int index, T newItem) → bool - Inserts an item at a specific index. Returns true if insertion was successful.
-
moveItem(
int fromIndex, int toIndex) → bool - Moves an item from one index to another. Returns true if move was successful.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onItemAdded(
T item, List< T> updatedList) → void - Called when an item is added to the list. Override this method to add custom logic after item addition.
-
onItemRemoved(
T item, List< T> updatedList) → void - Called when an item is removed from the list. Override this method to add custom logic after item removal.
-
onItemUpdated(
T oldItem, T newItem, List< T> updatedList) → void - Called when an item is updated in the list. Override this method to add custom logic after item update.
-
onListCleared(
List< T> previousList) → void - Called when the list is cleared. Override this method to add custom logic after list clear.
-
onListReplaced(
List< T> previousList, List<T> newList) → void - Called when the entire list is replaced. Override this method to add custom logic after list replacement.
-
removeIf(
bool predicate(T item)) → void - Removes items that match the predicate.
-
removeItem(
T item) → bool - Removes a specified item from the list. Calls onItemRemoved hook after removing. Returns true if item was found and removed.
-
removeItemAt(
int index) → T? - Removes an item at a specific index. Returns the removed item, or null if index is out of bounds.
-
replaceAll(
List< T> newItems) → void - Replaces all items with a new list.
-
replaceFirst(
T oldItem, T newItem) → bool - Replaces the first occurrence of an item with a new item. Returns true if replacement was successful.
-
reverse(
) → void - Reverses the order of items in the list.
-
swapItems(
int index1, int index2) → bool - Swaps two items at the specified indices. Returns true if swap was successful.
-
toString(
) → String -
A string representation of this object.
inherited
-
updateItem(
int index, T newItem) → bool - Updates an item at a specific index. Returns true if update was successful.
-
updateItemWhere(
bool predicate(T item), T newItem) → bool - Updates the first item matching the predicate. Returns true if update was successful.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited