SearchableDropdownPlus<C extends BlocBase<S>, S> class

A single-select searchable dropdown that integrates with any BLoC/Cubit.

Type Parameters

  • C — your Cubit/Bloc type, e.g. WorkerCubit
  • S — the state type emitted by C, e.g. WorkerState

Key Features

  • Real-time search via onSearch
  • Offline caching: falls back to client-side filtering when no internet
  • Controlled-mode support via selectedValue (useful for QR scan, form reset, etc.)
  • Full visual customisation via dropdownTheme or preset themeStyle
  • Custom item & selected-value builders

Basic Usage

SearchableDropdownPlus<WorkerCubit, WorkerState>(
  cubit: workerCubit,
  hintText: 'Search worker…',
  onSearch: workerCubit.search,
  onStateChange: (state, updateList, updateLoading) {
    if (state is WorkersLoaded) {
      updateList(state.workers
          .map((w) => DropdownItem(value: w, label: w.name))
          .toList());
      updateLoading(false);
    } else if (state is WorkersLoading) {
      updateLoading(true);
    }
  },
  onSelectionChanged: (item) => setState(() => _selected = item.value),
)

Controlled Mode (e.g. QR scan)

SearchableDropdownPlus(
  key: ValueKey(qrScanKey), // increment key to force re-sync
  selectedValue: scannedItem,
  ...
)
Inheritance

Constructors

SearchableDropdownPlus({required C cubit, required void onSearch(String query), required void onStateChange(S state, void updateList(List<DropdownItem>), void updateLoading(bool)), required String hintText, Key? key, DropdownItem? selectedValue, void onSelectionChanged(DropdownItem item)?, String? searchHint, String? noResultsText, String? loadingText, bool needInitialFetch = false, DropdownPlusTheme? dropdownTheme, DropdownPlusThemeStyle? themeStyle, Widget itemBuilder(DropdownItem item, bool isSelected)?, Widget selectedValueBuilder(DropdownItem selectedItem)?, Future<bool> checkInternetConnection()?, Duration debounceDuration = Duration.zero, bool enabled = true, bool autofocusSearch = false, DropdownEmptyBuilder? emptyBuilder, DropdownLoadingBuilder? loadingBuilder, Object? error, VoidCallback? onRetry, DropdownErrorBuilder? errorBuilder, String? semanticsLabel, int minSearchLength = 0, VoidCallback? onLoadMore, bool hasMore = false, bool isLoadingMore = false, FocusNode? focusNode, DropdownMenuController? menuController})
const

Properties

autofocusSearch bool
Focus the search field when the panel opens.
final
checkInternetConnection Future<bool> Function()?
Optional async function returning true when the device is online. When null, the widget always performs remote search (no offline fallback).
final
cubit → C
The BLoC/Cubit instance that drives this dropdown.
final
debounceDuration Duration
Debounce delay before onSearch is invoked. Default: no debounce.
final
Visual customisation. When null, themeStyle is used if set.
final
emptyBuilder DropdownEmptyBuilder?
Custom empty-state UI when there are no results.
final
enabled bool
When false, the dropdown cannot be opened or searched.
final
error Object?
Optional error to display in the panel (controlled mode).
final
errorBuilder DropdownErrorBuilder?
Custom error UI. Receives onRetry for retry actions.
final
focusNode FocusNode?
Optional focus node for the trigger button.
final
hashCode int
The hash code for this object.
no setterinherited
hasMore bool
Whether more items can be loaded via onLoadMore.
final
hintText String
Placeholder text shown when no item is selected.
final
isLoadingMore bool
Shows a loading footer while the next page loads.
final
itemBuilder Widget Function(DropdownItem item, bool isSelected)?
Override the item row rendering.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
loadingBuilder DropdownEmptyBuilder?
Custom loading UI while items are loading.
final
loadingText String?
Message shown while the cubit is loading.
final
Optional menu controller for programmatic open/close.
final
minSearchLength int
Minimum query length before onSearch is invoked (empty query always fires).
final
needInitialFetch bool
If true, onSearch is called with an empty string on widget mount.
final
noResultsText String?
Message shown when the search returns no results.
final
onLoadMore VoidCallback?
Called when the user scrolls near the bottom of the item list.
final
onRetry VoidCallback?
Called when the user taps retry in the default error UI.
final
onSearch → void Function(String query)
Called whenever the user types in the search box.
final
onSelectionChanged → void Function(DropdownItem item)?
Called when the user picks an item. Not called for programmatic updates via selectedValue.
final
onStateChange → void Function(S state, void updateList(List<DropdownItem>), void updateLoading(bool))
Maps incoming BLoC/Cubit states to list updates.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
searchHint String?
Hint text shown inside the search input. Defaults to 'Search…'.
final
selectedValue DropdownItem?
Pre-selected item (controlled mode). When provided, the parent owns the selection state.
final
selectedValueBuilder Widget Function(DropdownItem selectedItem)?
Override how the selected value is displayed in the trigger button.
final
semanticsLabel String?
Semantics label for the trigger button.
final
themeStyle DropdownPlusThemeStyle?
Preset theme style. Ignored when dropdownTheme is non-null. Use for out-of-the-box looks: DropdownPlusThemeStyle.minimal, DropdownPlusThemeStyle.dark, etc.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<SearchableDropdownPlus<C, S>>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

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