SmartSearchController<T> class
Controller for managing search state and connecting to SmartPaginationCubit.
This controller handles:
- Debounced search input
- Search query state management
- Connection to pagination cubit for data fetching
- Overlay visibility state
- Keyboard navigation (up/down arrows)
- Focus state persistence
Example:
final searchController = SmartSearchController<Product>(
cubit: productsCubit,
searchFieldBuilder: (query) => PaginationRequest(
page: 1,
pageSize: 20,
searchQuery: query,
),
);
- Inheritance
-
- Object
- ChangeNotifier
- SmartSearchController
Constructors
-
SmartSearchController({required SmartPaginationCubit<
T> cubit, required PaginationRequest searchRequestBuilder(String query), SmartSearchConfig config = const SmartSearchConfig(), ValueChanged<T> ? onItemSelected})
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
- hasText → bool
-
Whether the search field has text.
no setter
- isOverlayVisible → bool
-
Whether the overlay is currently visible.
no setter
- isSearching → bool
-
Whether a search is currently in progress.
no setter
-
onItemSelected
← ValueChanged<
T> ? -
Sets the item selection callback.
no getter
- query → String
-
The current search query text.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- textController → TextEditingController
-
The text editing controller for the search field.
no setter
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
clearItemFocus(
) → void - Clears the item focus (sets to -1).
-
clearSearch(
) → void - Clears the search text and resets the query.
-
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
-
handleKeyEvent(
KeyEvent event) → bool - Handles keyboard events for navigation. Returns true if the event was handled.
-
hideOverlay(
) → void - Hides the search overlay.
-
moveToFirstItem(
) → void - Moves focus to the first item.
-
moveToLastItem(
) → void - Moves focus to the last item.
-
moveToNextItem(
) → bool - Moves focus to the next item in the list. Returns true if focus was moved, false if at the end.
-
moveToPreviousItem(
) → bool - Moves focus to the previous item in the list. Returns true if focus was moved, false if at the beginning.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
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. Returns the item if one was focused and selected, null otherwise.
-
selectItem(
T item) → void - Selects an item from the search results. This will hide the overlay, call the onItemSelected callback, and optionally clear the search.
-
setFocusedIndex(
int index) → void - Sets focus to a specific index.
-
setSearchText(
String text) → void - Sets the search text programmatically.
-
showOverlay(
) → void - Shows the search overlay.
-
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