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.
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
Blocof a neweventwhich triggers all correspondingEventHandlerinstances.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
errorwhich triggersonErrorwith 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
eventandstateStreams. This method should be called when aBlocis no longer needed. Once close is called,eventsthat are added will not be processed. In addition, if close is called whileeventsare still being processed, theBlocwill finish processing the pendingevents. -
containsItem(
User item) → bool -
Checks if the list contains a specified item.
inherited
-
emit(
UsersState state) → void -
emitis only for internal use and should never be called directly outside of tests. TheEmitterinstance provided to eachEventHandlershould 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 typeE.inherited -
onChange(
Change< UsersState> change) → void -
Called whenever a
changeoccurs with the givenchange. Achangeoccurs when a newstateis emitted.onChangeis called before thestateof thecubitis updated.onChangeis a great spot to add logging/analytics for a specificcubit.inherited -
onError(
Object error, StackTrace stackTrace) → void -
Called whenever an
erroroccurs and notifiesBlocObserver.onError.inherited -
onEvent(
UsersEvent event) → void -
Called whenever an
eventisadded to theBloc. A great spot to add logging/analytics at the individualBloclevel.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
transitionoccurs with the giventransition. Atransitionoccurs when a neweventis added and a new state isemittedfrom a correspondingEventHandler.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