UsersBloc class

BLoC for managing users list

This BLoC manages the users list state and handles:

  • Loading and pagination of users
  • Real-time updates via SDK listeners (user online/offline)
  • Selection management
  • Search functionality with debouncing

This BLoC uses the ListBase mixin for list management operations. Developers can extend this class and override the hook methods (onItemAdded, onItemRemoved, onItemUpdated, onListCleared, onListReplaced) to add custom logic like sorting, filtering, or validation.

Mixed-in types

Constructors

UsersBloc({GetUsersUseCase? getUsersUseCase, GetLoggedInUserUseCase? getLoggedInUserUseCase, bool usersStatusVisibility = true, bool includeBlockedUsers = false, bool disableSDKListeners = false, UsersRequestBuilder? usersRequestBuilder})
Creates a UsersBloc.

Properties

disableSDKListeners bool
Whether to disable SDK listeners
final
getLoggedInUserUseCase GetLoggedInUserUseCase
final
getUsersUseCase GetUsersUseCase
final
hashCode int
The hash code for this object.
no setterinherited
includeBlockedUsers bool
final
isClosed bool
Whether the bloc is closed.
no setterinherited
isEmpty bool
Returns true if the list is empty
no setterinherited
isNotEmpty bool
Returns true if the list is not empty
no setterinherited
itemCount int
Returns the number of items in the list
no setterinherited
items List<User>
Returns an unmodifiable view of the current items
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state UsersState
The current state.
no setterinherited
stream Stream<UsersState>
The current stream of states.
no setterinherited
usersRequestBuilder UsersRequestBuilder?
Custom users request builder for filtering users
final
usersStatusVisibility bool
final

Methods

add(UsersEvent event) → void
Notifies the Bloc of a new event which triggers all corresponding EventHandler instances.
inherited
addAllItems(List<User> itemsToAdd) → void
Adds multiple items to the end of the list. Calls onItemAdded hook for each item.
inherited
addAllItemsAtStart(List<User> itemsToAdd) → void
Adds items at the beginning of the list.
inherited
addError(Object error, [StackTrace? stackTrace]) → void
Reports an error which triggers onError with an optional StackTrace.
inherited
addItem(User item) → void
Adds an item to the end of the list. Calls onItemAdded hook after adding.
inherited
addUniqueItem(User item) bool
Adds an item only if it doesn't already exist in the list. Returns true if item was added.
inherited
clearItems() → void
Clears all items from the list.
inherited
close() Future<void>
Closes the event and state Streams. This method should be called when a Bloc is no longer needed. Once close is called, events that are added will not be processed. In addition, if close is called while events are still being processed, the Bloc will finish processing the pending events.
containsItem(User item) bool
Checks if the list contains a specified item.
inherited
emit(UsersState state) → void
emit is only for internal use and should never be called directly outside of tests. The Emitter instance provided to each EventHandler should be used instead.
inherited
filterItems(bool predicate(User)) → void
Filters items based on a predicate. Removes items that don't match the predicate.
inherited
findFirst(bool predicate(User)) User?
Finds the first item matching the predicate. Returns null if no item matches.
inherited
findIndex(bool predicate(User)) int
Finds the index of the first item matching the predicate. Returns -1 if no item matches.
inherited
getItemAt(int index) User?
Retrieves an item at a specific index safely. Returns null if index is out of bounds.
inherited
getStatusNotifier(String uid) ValueNotifier<String>
Get or create a status notifier for a specific user. Use this with ValueListenableBuilder in list items for isolated rebuilds.
getUserStatus(String uid) String
Get current status for a user
insertItemAt(int index, User newItem) bool
Inserts an item at a specific index. Returns true if insertion was successful.
inherited
moveItem(int fromIndex, int toIndex) bool
Moves an item from one index to another. Returns true if move was successful.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
on<E extends Event>(EventHandler<E, UsersState> handler, {EventTransformer<E>? transformer}) → void
Register event handler for an event of type E. There should only ever be one event handler per event type E.
inherited
onChange(Change<UsersState> 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
onEvent(UsersEvent event) → void
Called whenever an event is added to the Bloc. A great spot to add logging/analytics at the individual Bloc level.
inherited
onItemAdded(User item, List<User> updatedList) → void
Called when an item is added to the list. Override this method to add custom logic after item addition.
override
onItemRemoved(User item, List<User> updatedList) → void
Called when an item is removed from the list. Override this method to add custom logic after item removal.
override
onItemUpdated(User oldItem, User newItem, List<User> updatedList) → void
Called when an item is updated in the list. Override this method to add custom logic after item update.
override
onListCleared(List<User> previousList) → void
Called when the list is cleared. Override this method to add custom logic after list clear.
override
onListReplaced(List<User> previousList, List<User> newList) → void
Called when the entire list is replaced. Override this method to add custom logic after list replacement.
override
onTransition(Transition<UsersEvent, UsersState> transition) → void
Called whenever a transition occurs with the given transition. A transition occurs when a new event is added and a new state is emitted from a corresponding EventHandler.
inherited
removeIf(bool predicate(User)) → void
Removes items that match the predicate.
inherited
removeItem(User item) bool
Removes a specified item from the list. Calls onItemRemoved hook after removing. Returns true if item was found and removed.
inherited
removeItemAt(int index) User?
Removes an item at a specific index. Returns the removed item, or null if index is out of bounds.
inherited
replaceAll(List<User> newItems) → void
Replaces all items with a new list.
inherited
replaceFirst(User oldItem, User newItem) bool
Replaces the first occurrence of an item with a new item. Returns true if replacement was successful.
inherited
reverse() → void
Reverses the order of items in the list.
inherited
swapItems(int index1, int index2) bool
Swaps two items at the specified indices. Returns true if swap was successful.
inherited
toString() String
A string representation of this object.
inherited
updateItem(int index, User newItem) bool
Updates an item at a specific index. Returns true if update was successful.
inherited
updateItemWhere(bool predicate(User), User newItem) bool
Updates the first item matching the predicate. Returns true if update was successful.
inherited

Operators

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