SearchChoices<T> class

SearchChoices widget that allows the opening of a searchable dropdown. Use the SearchChoices.single factory if only one item needs to be selected. Use the SearchChoices.multiple factory if user must be able to select multiple items at once.

Inheritance

Constructors

SearchChoices.multiple({Key? key, List<DropdownMenuItem<T>>? items, Function? onChanged, List<int> selectedItems = const [], TextStyle? style, dynamic searchHint, dynamic hint, dynamic disabledHint, dynamic icon = const Icon(Icons.arrow_drop_down), dynamic underline, dynamic doneButton = "Done", dynamic label, dynamic closeButton = "Close", bool displayClearIcon = true, Icon clearIcon = const Icon(Icons.clear), Color? iconEnabledColor, Color? iconDisabledColor, double iconSize = 24.0, bool isExpanded = false, bool isCaseSensitiveSearch = false, Function? searchFn, Function? onClear, Function? selectedValueWidgetFn, TextInputType keyboardType = TextInputType.text, String? validator(T?)?, Function? displayItem, bool dialogBox = true, BoxConstraints? menuConstraints, bool readOnly = false, Color? menuBackgroundColor, bool? rightToLeft, bool autofocus = true, Function? selectedAggregateWidgetFn, dynamic padding, Function? setOpenDialog, Widget buildDropDownDialog(Widget titleBar, Widget searchBar, Widget list, Widget closeButton, BuildContext dropDownContext)?, EdgeInsets? dropDownDialogPadding, InputDecoration? searchInputDecoration, int? itemsPerPage, PointerThisPlease<int>? currentPage, Widget customPaginationDisplay(Widget listWidget, int totalFilteredItemsNb, Function updateSearchPage)?, Future<Tuple2<List<DropdownMenuItem>, int>> futureSearchFn(String? keyword, String? orderBy, bool? orderAsc, List<Tuple2<String, String>>? filters, int? pageNb)?, Map<String, Map<String, dynamic>>? futureSearchOrderOptions, Map<String, Map<String, Object>>? futureSearchFilterOptions, List<T>? futureSelectedValues, dynamic emptyListWidget, Function? onTap, Function? futureSearchRetryButton, int? searchDelay, Widget fieldPresentationFn(Widget fieldWidget, {bool selectionIsValid})?, Decoration? fieldDecoration, Widget? clearSearchIcon, Future<void> showDialogFn(BuildContext context, Widget menuWidget({String searchTerms}), String searchTerms)?, FormFieldSetter<T>? onSaved, String? listValidator(List<T?>)?, AutovalidateMode autovalidateMode = AutovalidateMode.onUserInteraction, String? restorationId, dynamic giveMeThePop(Function pop)?, Widget buildFutureFilterOrOrderButton({required BuildContext context, required bool filter, int? nbFilters, required Function onPressed, bool? orderAsc, String? orderBy})?, Widget searchResultDisplayFn({required Widget displayItem(DropdownMenuItem item, bool isItemSelected), required Widget emptyListWidget, required void itemTapped(int index, T value, bool itemSelected), required List<Tuple3<int, DropdownMenuItem, bool>> itemsToDisplay, required ScrollController scrollController, required bool thumbVisibility})?})
Search choices Widget with a multiple choice that opens a dialog or a menu to let the user do the selection conveniently with a search.
SearchChoices.single({Key? key, List<DropdownMenuItem<T>>? items, Function? onChanged, T? value, TextStyle? style, dynamic searchHint, dynamic hint, dynamic disabledHint, dynamic icon = const Icon(Icons.arrow_drop_down), dynamic underline, dynamic doneButton, dynamic label, dynamic closeButton = "Close", bool displayClearIcon = true, Icon clearIcon = const Icon(Icons.clear), Color? iconEnabledColor, Color? iconDisabledColor, double iconSize = 24.0, bool isExpanded = false, bool isCaseSensitiveSearch = false, Function? searchFn, Function? onClear, Function? selectedValueWidgetFn, TextInputType keyboardType = TextInputType.text, String? validator(T?)?, @deprecated bool assertUniqueValue = true, Function? displayItem, bool dialogBox = true, BoxConstraints? menuConstraints, bool readOnly = false, Color? menuBackgroundColor, bool? rightToLeft, bool autofocus = true, Function? selectedAggregateWidgetFn, dynamic padding, Function? setOpenDialog, Widget buildDropDownDialog(Widget titleBar, Widget searchBar, Widget list, Widget closeButton, BuildContext dropDownContext)?, EdgeInsets? dropDownDialogPadding, InputDecoration? searchInputDecoration, int? itemsPerPage, PointerThisPlease<int>? currentPage, Widget customPaginationDisplay(Widget listWidget, int totalFilteredItemsNb, Function updateSearchPage)?, Future<Tuple2<List<DropdownMenuItem>, int>> futureSearchFn(String? keyword, String? orderBy, bool? orderAsc, List<Tuple2<String, String>>? filters, int? pageNb)?, Map<String, Map<String, dynamic>>? futureSearchOrderOptions, Map<String, Map<String, Object>>? futureSearchFilterOptions, dynamic emptyListWidget, Function? onTap, Function? futureSearchRetryButton, int? searchDelay, Widget fieldPresentationFn(Widget fieldWidget, {bool selectionIsValid})?, Decoration? fieldDecoration, Widget? clearSearchIcon, Future<void> showDialogFn(BuildContext context, Widget menuWidget({String searchTerms}), String searchTerms)?, FormFieldSetter<T>? onSaved, AutovalidateMode autovalidateMode = AutovalidateMode.onUserInteraction, String? restorationId, dynamic giveMeThePop(Function pop)?, Widget buildFutureFilterOrOrderButton({required BuildContext context, required bool filter, int? nbFilters, required Function onPressed, bool? orderAsc, String? orderBy})?, Widget searchResultDisplayFn({required Widget displayItem(DropdownMenuItem item, bool isItemSelected), required Widget emptyListWidget, required void itemTapped(int index, T value, bool itemSelected), required List<Tuple3<int, DropdownMenuItem, bool>> itemsToDisplay, required ScrollController scrollController, required bool thumbVisibility})?})
Search choices Widget with a single choice that opens a dialog or a menu to let the user do the selection conveniently with a search.

Properties

autofocus bool
autofocus bool automatically focuses on the search field bringing up the keyboard defaulted to true.
final
autovalidateMode AutovalidateMode
autovalidateMode as in FormField.
final
buildDropDownDialog → (Widget Function(Widget titleBar, Widget searchBar, Widget list, Widget closeButton, BuildContext dropDownContext)?)
buildDropDownDialog Function controls the layout of the dropdown dialog. If null, equivalent to:
final
builder FormFieldBuilder<T>
Function that returns the widget representing this form field. It is passed the form field state as input, containing the current value and validation state of this field.
finalinherited
buildFutureFilterOrOrderButton → (Widget Function({required BuildContext context, required bool filter, int? nbFilters, required Function onPressed, bool? orderAsc, String? orderBy})?)
buildFutureFilterOrOrderButton Function to customize the order and filter button in case of future search. Where:
final
clearIcon Icon
clearIcon Icon to be used for clearing the selected value.
final
clearSearchIcon Widget?
clearSearchIcon Widget sets the icon to be used to clear the search.
final
closeButton → dynamic
closeButton String|Widget|Function with parameter: value returning String|Widget displayed at the bottom of the search dialog box.
final
currentPage PointerThisPlease<int>?
currentPage PointerThisPlease<int> if itemsPerPage is set, holds the page number for the search items to be displayed.
final
customPaginationDisplay → (Widget Function(Widget listWidget, int totalFilteredItemsNb, Function updateSearchPage)?)
customPaginationDisplay Widget Function(Widget listWidget, int totalFilteredItemsNb, Function updateSearchPage) if itemsPerPage is set, customizes the display and the handling of the pagination on the search list.
final
dialogBox bool
dialogBox whether the search should be displayed as a dialog box or as a menu below the selected value if any.
final
disabledHint → dynamic
disabledHint String|Widget|Function with no parameter returning String|Widget displayed instead of hint when the widget is displayed.
final
displayClearIcon bool
displayClearIcon whether or not to display an icon to clear the selected value.
final
displayItem Function?
displayItem Function with parameters: item, selected returning Widget to be displayed in the search list.
final
doneButton → dynamic
doneButton String|Widget|Function with parameter: value returning String|Widget displayed at the top of the search dialog box.
final
dropDownDialogPadding EdgeInsets sets the padding between the screen and the dialog.
final
emptyListWidget → dynamic
emptyListWidget String|Widget|Function with parameter: keyword returning String|Widget displayed instead of the list of items in case it is empty.
final
enabled bool
Whether the form is able to receive user input.
finalinherited
fieldDecoration Decoration?
fieldDecoration Decoration is the decoration of the SearchChoices Widget while displaying the hints or the selected values. Should differ when selection is not valid.
final
fieldPresentationFn → (Widget Function(Widget fieldWidget, {bool selectionIsValid})?)
fieldPresentationFn Function returning a Widget to customize the display of the field.
final
futureSearchFilterOptions Map<String, Map<String, Object>>?
futureSearchFilterOptions Map<String, Map<String, Object>> when futureSearchFn is set, can be used to display search filters specified in the form {"filter1Name": {"icon":filter1IconWidget, "values":["value1",{"value2":filter1Value2Widget}}}. Please refer to the documentation example: https://github.com/lcuis/search_choices/blob/master/example/lib/main.dart.
final
futureSearchFn → (Future<Tuple2<List<DropdownMenuItem>, int>> Function(String? keyword, String? orderBy, bool? orderAsc, List<Tuple2<String, String>>? filters, int? pageNb)?)
futureSearchFn Future
final
futureSearchOrderOptions Map<String, Map<String, dynamic>>?
futureSearchOrderOptions Map<String, Map<String,dynamic>> when futureSearchFn is set, can be used to display search order options specified in the form {"order1Name":{"icon":order1IconWidget,"asc":true},}. Please refer to the documentation example: https://github.com/lcuis/search_choices/blob/master/example/lib/main.dart.
final
futureSearchRetryButton Function?
futureSearchRetryButton Function called to customize the Error - retry button displayed when there is an issue with the future search.
final
futureSelectedValues List<T>?
futureSelectedValues List<T> contains the list of selected values in case of future search in multiple selection mode.
final
giveMeThePop → (dynamic Function(Function pop)?)
giveMeThePop Function to pass the pop function so that the menu or dialog can be closed from outside the widget.
final
hashCode int
The hash code for this object.
no setterinherited
hint → dynamic
hint String|Widget|Function with no parameter returning String|Widget displayed before any value is selected or after the selection is cleared.
final
icon → dynamic
icon String|Widget|Function with parameter: value returning String|Widget displayed next to the selected item or the hint if none.
final
iconDisabledColor Color?
iconDisabledColor Color to be used for disabled icons.
final
iconEnabledColor Color?
iconEnabledColor Color to be used for enabled icons.
final
iconSize double
iconSize for the icons next to the selected value (icon and clearIcon).
final
initialValue → T?
An optional value to initialize the form field to, or null otherwise.
finalinherited
isCaseSensitiveSearch bool
isCaseSensitiveSearch only used when searchFn is not specified.
final
isEnabled bool
no setter
isExpanded bool
isExpanded can be necessary to avoid pixel overflows (zebra symptom).
final
items List<DropdownMenuItem<T>>?
items with child: Widget displayed ; value: any object with .toString() used to match search keyword.
final
itemsPerPage int?
itemsPerPage int if set, organizes the search list per page with the given number of items displayed per page. Must give currentPage.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
keyboardType TextInputType
keyboardType used for the search.
final
label → dynamic
label String|Widget|Function with parameter: value returning String|Widget displayed above the selected item or the hint if none.
final
listValidator → (String? Function(List<T?>)?)
listValidator Function with parameter: List returning String displayed below selected value when not valid and null when valid.
final
menuBackgroundColor Color background color of the menu whether in dialog box or menu mode.
final
menuConstraints BoxConstraints used to define the zone where to display the search menu. Example: BoxConstraints.tight(Size.fromHeight(250)) . Not to be used for dialogBox = true.
final
multipleSelection bool
multipleSelection indicates whether user can select one or more items.
final
onChanged Function?
onChanged Function with parameter: value not returning executed after the selection is done.
final
onClear Function?
onClear Function with no parameter not returning executed when the clear icon is tapped.
final
onSaved FormFieldSetter<T>?
onSaved as in FormField.
final
onTap Function?
onTap Function called when the user clicks on the Widget before it opens the dialog or the menu. Note that this is not called in case the Widget is disabled.
final
padding → dynamic
padding double or EdgeInsets sets the padding around the DropdownButton, defaulted to 10.0.
final
readOnly bool
readOnly bool whether to let the user choose the value to select or just present the selected value if any.
final
restorationId String?
restorationId as in FormField.
final
rightToLeft bool?
rightToLeft bool mirrors the widgets display for right to left languages defaulted to app.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
searchDelay int?
searchDelay int in milliseconds applied before the search is initiated. This applies to future and non-future searches.
final
searchFn Function?
searchFn Function with parameters: keyword, items returning List<int> as the list of indexes for the items to be displayed.
final
searchHint → dynamic
searchHint String|Widget|Function with no parameter returning String|Widget displayed at the top of the search dialog box.
final
searchInputDecoration InputDecoration?
searchInputDecoration InputDecoration sets the search bar decoration.
final
searchResultDisplayFn → (Widget Function({required Widget displayItem(DropdownMenuItem item, bool isItemSelected), required Widget emptyListWidget, required void itemTapped(int index, T value, bool itemSelected), required List<Tuple3<int, DropdownMenuItem, bool>> itemsToDisplay, required ScrollController scrollController, required bool thumbVisibility})?)
searchResultDisplayFn to customize the display of the search result items within the dialog or menu. Example: searchResultDisplayFn: ({ required List<Tuple3<int, DropdownMenuItem, bool>> itemsToDisplay, required ScrollController scrollController, required bool thumbVisibility, required Widget emptyListWidget, required void Function(int index, dynamic value, bool itemSelected) itemTapped, required Widget Function(DropdownMenuItem item, bool isItemSelected) displayItem, }) { return Expanded( child: itemsToDisplay.length == 0 ? emptyListWidget : SingleChildScrollView( child: Wrap( spacing: 10, children: itemsToDisplay.map( (Tuple3<int, DropdownMenuItem, bool> item) { return Padding( padding: const EdgeInsets.symmetric(vertical: 8.0), child: InkWell( onTap: () { itemTapped( item.item1, item.item2.value, item.item3, ); }, child: Container( decoration: BoxDecoration( border: Border.all( color: Colors.grey, width: 5, )), child: Row( mainAxisSize: MainAxisSize.min, children: Padding( padding: const EdgeInsets.symmetric( horizontal: 8.0), child: item.item2, ), , ), ), ), ); }, ).toList()), )); },
final
selectedAggregateWidgetFn Function?
selectedAggregateWidgetFn Function with parameter: list of widgets presenting selected values , returning Widget to be displayed to present the selected items.
final
selectedItems List<int>
selectedItems indexes of items to be preselected.
final
selectedValueWidgetFn Function?
selectedValueWidgetFn Function with parameter: item returning Widget to be used to display the selected value.
final
setOpenDialog Function?
setOpenDialog Function sets the function to call to set the function to call in order to open the dialog with the search terms string as a parameter, defaulted to null.
final
showDialogFn → (Future<void> Function(BuildContext context, Widget menuWidget({String searchTerms}), String searchTerms)?)
showDialogFn Function allows the control of the dialog display.
final
style TextStyle?
style used for the hint if it is given is String.
final
underline → dynamic
underline String|Widget|Function with parameter: value returning String|Widget displayed below the selected item or the hint if none.
final
validator → (String? Function(T?)?)
validator Function with parameter: value returning String displayed below selected value when not valid and null when valid.
final
value → T?
value value to be preselected.
final

Methods

checkPreconditions() → dynamic
createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → _SearchChoicesState<T>
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}) 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

Static Properties

dialogBoxMenuWrapper ↔ (Widget Function(Widget)?)
dialogBoxMenuWrapper Function called to wrap the menu widget when in dialog box mode. This is useful for testing mainly.
getter/setter pair