GroupsBloc class

BLoC for managing groups list

This BLoC manages the groups list state and handles:

  • Loading and pagination of groups
  • Real-time updates via SDK listeners (member joined, left, kicked, banned, scope changed)
  • Selection management
  • Search functionality

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.

Requirements: 1.1, 1.2, 1.5, 8.3, 8.4

Mixed-in types

Constructors

GroupsBloc({GetGroupsUseCase? getGroupsUseCase, LoadMoreGroupsUseCase? loadMoreGroupsUseCase, GetLoggedInUserUseCase? getLoggedInUserUseCase, bool disableSDKListeners = false})
Creates a GroupsBloc.

Properties

disableSDKListeners bool
Whether to disable SDK listeners
final
getGroupsUseCase GetGroupsUseCase
final
getLoggedInUserUseCase GetLoggedInUserUseCase
final
hashCode int
The hash code for this object.
no setterinherited
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<Group>
Returns an unmodifiable view of the current items
no setterinherited
loadMoreGroupsUseCase LoadMoreGroupsUseCase
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state GroupsState
The current state.
no setterinherited
stream Stream<GroupsState>
The current stream of states.
no setterinherited

Methods

add(GroupsEvent event) → void
Notifies the Bloc of a new event which triggers all corresponding EventHandler instances.
inherited
addAllItems(List<Group> itemsToAdd) → void
Adds multiple items to the end of the list. Calls onItemAdded hook for each item.
inherited
addAllItemsAtStart(List<Group> 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(Group item) → void
Adds an item to the end of the list. Calls onItemAdded hook after adding.
inherited
addUniqueItem(Group 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(Group item) bool
Checks if the list contains a specified item.
inherited
emit(GroupsState 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(Group)) → void
Filters items based on a predicate. Removes items that don't match the predicate.
inherited
findFirst(bool predicate(Group)) Group?
Finds the first item matching the predicate. Returns null if no item matches.
inherited
findGroup(String guid) Group?
Find a group by its GUID using O(1) lookup
findGroupIndex(String guid) int?
Find the index of a group by its GUID using O(1) lookup
findIndex(bool predicate(Group)) int
Finds the index of the first item matching the predicate. Returns -1 if no item matches.
inherited
getItemAt(int index) Group?
Retrieves an item at a specific index safely. Returns null if index is out of bounds.
inherited
getSelectedGroups() List<Group>
Get the list of selected Group objects
insertItemAt(int index, Group 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, GroupsState> 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<GroupsState> 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(GroupsEvent 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(Group item, List<Group> updatedList) → void
Called when an item is added to the list. Override this method to add custom logic after item addition.
override
onItemRemoved(Group item, List<Group> updatedList) → void
Called when an item is removed from the list. Override this method to add custom logic after item removal.
override
onItemUpdated(Group oldItem, Group newItem, List<Group> updatedList) → void
Called when an item is updated in the list. Override this method to add custom logic after item update.
override
onListCleared(List<Group> previousList) → void
Called when the list is cleared. Override this method to add custom logic after list clear.
override
onListReplaced(List<Group> previousList, List<Group> newList) → void
Called when the entire list is replaced. Override this method to add custom logic after list replacement.
override
onTransition(Transition<GroupsEvent, GroupsState> 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(Group)) → void
Removes items that match the predicate.
inherited
removeItem(Group 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) Group?
Removes an item at a specific index. Returns the removed item, or null if index is out of bounds.
inherited
replaceAll(List<Group> newItems) → void
Replaces all items with a new list.
inherited
replaceFirst(Group oldItem, Group 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, Group newItem) bool
Updates an item at a specific index. Returns true if update was successful.
inherited
updateItemWhere(bool predicate(Group), Group 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