SmartSearchMultiController<T, K> class

Controller for managing multi-selection search state.

This controller handles:

  • Multiple item selection from search results
  • Search query state management
  • Connection to pagination cubit for data fetching
  • Overlay visibility state
  • Keyboard navigation
  • Key-based selection with automatic data synchronization

The controller supports two generic types:

  • T: The data type of items (e.g., Product, User)
  • K: The key type used for identification (e.g., String, int)

Example with key-based selection:

final controller = SmartSearchMultiController<Product, String>(
  cubit: productsCubit,
  searchRequestBuilder: (query) => PaginationRequest(
    page: 1,
    pageSize: 20,
    searchQuery: query,
  ),
  keyExtractor: (product) => product.sku,
  selectedKeys: ['SKU-001', 'SKU-002', 'SKU-003'],
  selectedKeyLabelBuilder: (key) => 'Product: $key',
  onSelected: (items, keys) => print('Selected ${items.length} items'),
);
Inheritance

Constructors

SmartSearchMultiController({required SmartPaginationCubit<T> cubit, required PaginationRequest searchRequestBuilder(String query), SmartSearchConfig config = const SmartSearchConfig(), void onSelected(List<T> items, List<K> keys)?, List<T>? initialSelectedValues, List<K>? selectedKeys, K keyExtractor(T item)?, String selectedKeyLabelBuilder(K key)?, int? maxSelections})

Properties

config SmartSearchConfig
The current search configuration.
no setter
cubit SmartPaginationCubit<T>
The connected pagination cubit.
no setter
focusedIndex int
The index of the currently focused item (-1 if none).
no setter
focusedItem → T?
Returns the currently focused item, or null if none.
no setter
focusNode FocusNode
The focus node for the search field.
no setter
hasFocus bool
Whether the search field has focus.
no setter
hashCode int
The hash code for this object.
no setterinherited
hasItemFocus bool
Whether an item is currently focused.
no setter
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
hasPendingKeys bool
Whether there are any pending keys that haven't been resolved yet.
no setter
hasSelectedItems bool
Whether any items are selected.
no setter
hasText bool
Whether the search field has text.
no setter
isMaxSelectionsReached bool
Whether max selections has been reached.
no setter
isOverlayVisible bool
Whether the overlay is currently visible.
no setter
isSearching bool
Whether a search is currently in progress.
no setter
keyExtractor → K Function(T item)?
The key extractor function.
no setter
maxSelections int?
Maximum number of items that can be selected.
no setter
onSelected ← void Function(List<T> items, List<K> keys)?
Sets the selection callback.
no getter
pendingKeys Set<K>
The set of pending keys (unmodifiable).
no setter
query String
The current search query text.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selectedItems List<T>
The list of currently selected items (unmodifiable).
no setter
selectedKeys List<K>
The list of currently selected keys (unmodifiable).
no setter
selectionCount int
The number of selected items.
no setter
textController TextEditingController
The text editing controller for the search field.
no setter
totalSelectionCount int
The number of selected keys (including pending ones).
no setter

Methods

addByKey(K key) → void
Adds an item by its key. If the item is already loaded, it will be added immediately. Otherwise, the key will be stored as pending.
addItem(T item) → void
Adds an item to the selection.
addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
clearAllSelections() → void
Clears all selected items.
clearItemFocus() → void
Clears the item focus.
clearSearch() → void
Clears the search text.
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
override
getKeyLabel(K key) String
Returns the display label for a specific key.
handleKeyEvent(KeyEvent event) bool
Handles keyboard events for navigation.
hideOverlay() → void
Hides the search overlay.
isItemSelected(T item) bool
Checks if an item is selected.
isKeyPending(K key) bool
Checks if a key is pending (not yet resolved to an item).
isKeySelected(K key) bool
Checks if a key is currently selected.
moveToFirstItem() → void
Moves focus to the first item.
moveToLastItem() → void
Moves focus to the last item.
moveToNextItem() bool
Moves focus to the next item.
moveToPreviousItem() bool
Moves focus to the previous item.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
removeByKey(K key) → void
Removes an item by its key.
removeItem(T item) → void
Removes an item from the selection.
removeItemAt(int index) → void
Removes an item at the given index.
removeKeyAt(int index) → void
Removes a key at the given index.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
requestFocus() → void
Requests focus on the search field.
searchNow() → void
Triggers an immediate search with the current text.
selectFocusedItem() → T?
Selects the currently focused item.
setFocusedIndex(int index) → void
Sets focus to a specific index.
setSearchText(String text) → void
Sets the search text programmatically.
setSelectedItems(List<T> items) → void
Sets the selected items programmatically.
setSelectedKeys(List<K> keys) → void
Sets the selected keys programmatically. This will try to resolve to items if data is loaded.
showOverlay() → void
Shows the search overlay.
toggleItemSelection(T item) → void
Toggles selection of an item.
toggleKeySelection(K key) → void
Toggles selection by key.
toggleOverlay() → void
Toggles the overlay visibility.
toString() String
A string representation of this object.
inherited
unfocus() → void
Removes focus from the search field.

Operators

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