SearchableDropdownPlus<C extends StateStreamableSource<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()?})
const

Properties

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
Visual customisation. When null, themeStyle is used if set.
final
hashCode int
The hash code for this object.
no setterinherited
hintText String
Placeholder text shown when no item is selected.
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
loadingText String?
Message shown while the cubit is loading.
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
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
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