SearchChoices<T>.single constructor Null safety

SearchChoices<T>.single(
  1. {Key? key,
  2. required List<DropdownMenuItem<T>> items,
  3. Function? onChanged,
  4. T? value,
  5. TextStyle? style,
  6. dynamic searchHint,
  7. dynamic hint,
  8. dynamic disabledHint,
  9. dynamic icon = const Icon(Icons.arrow_drop_down),
  10. dynamic underline,
  11. dynamic doneButton,
  12. dynamic label,
  13. dynamic closeButton = "Close",
  14. bool displayClearIcon = true,
  15. Icon clearIcon = const Icon(Icons.clear),
  16. Color? iconEnabledColor,
  17. Color? iconDisabledColor,
  18. double iconSize = 24.0,
  19. bool isExpanded = false,
  20. bool isCaseSensitiveSearch = false,
  21. Function? searchFn,
  22. Function? onClear,
  23. Function? selectedValueWidgetFn,
  24. TextInputType keyboardType = TextInputType.text,
  25. Function? validator,
  26. bool assertUniqueValue = true,
  27. Function? displayItem,
  28. bool dialogBox = true,
  29. BoxConstraints? menuConstraints,
  30. bool readOnly = false,
  31. Color? menuBackgroundColor,
  32. bool rightToLeft = false,
  33. bool autofocus = true,
  34. Function? selectedAggregateWidgetFn,
  35. double padding = 10.0,
  36. Function? setOpenDialog}
)

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.

  • items with child: Widget displayed ; value: any object with .toString() used to match search keyword.
  • onChanged Function with parameter: value not returning executed after the selection is done.
  • value value to be preselected.
  • style used for the hint if it is given is String.
  • searchHint String|Widget|Function with no parameter returning String|Widget displayed at the top of the search dialog box.
  • hint String|Widget|Function with no parameter returning String|Widget displayed before any value is selected or after the selection is cleared.
  • disabledHint String|Widget|Function with no parameter returning String|Widget displayed instead of hint when the widget is displayed.
  • icon String|Widget|Function with parameter: value returning String|Widget displayed next to the selected item or the hint if none.
  • underline String|Widget|Function with parameter: value returning String|Widget displayed below the selected item or the hint if none.
  • doneButton String|Widget|Function with parameter: value returning String|Widget displayed at the top of the search dialog box.
  • label String|Widget|Function with parameter: value returning String|Widget displayed above the selected item or the hint if none.
  • closeButton String|Widget|Function with parameter: value returning String|Widget displayed at the bottom of the search dialog box.
  • displayClearIcon whether or not to display an icon to clear the selected value.
  • clearIcon Icon to be used for clearing the selected value.
  • iconEnabledColor Color to be used for enabled icons.
  • iconDisabledColor Color to be used for disabled icons.
  • iconSize for the icons next to the selected value (icon and clearIcon).
  • isExpanded can be necessary to avoid pixel overflows (zebra symptom).
  • isCaseSensitiveSearch only used when searchFn is not specified.
  • searchFn Function with parameters: keyword, items returning List<int> as the list of indexes for the items to be displayed.
  • onClear Function with no parameter not returning executed when the clear icon is tapped.
  • selectedValueWidgetFn Function with parameter: item returning Widget to be used to display the selected value.
  • keyboardType used for the search.
  • validator Function with parameter: value returning String displayed below selected value when not valid and null when valid.
  • assertUniqueValue whether to run a consistency check of the list of items.
  • displayItem Function with parameters: item, selected returning Widget to be displayed in the search list.
  • dialogBox whether the search should be displayed as a dialog box or as a menu below the selected value if any.
  • 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.
  • readOnly bool whether to let the user choose the value to select or just present the selected value if any.
  • menuBackgroundColor Color background color of the menu whether in dialog box or menu mode.
  • rightToLeft bool mirrors the widgets display for right to left languages defaulted to false.
  • autofocus bool automatically focuses on the search field bringing up the keyboard defaulted to true.
  • selectedAggregateWidgetFn Function with parameter: list of widgets presenting selected values , returning Widget to be displayed to present the selected items.
  • padding double sets the padding around the DropdownButton, defaulted to 10.0.
  • 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.

Implementation

factory SearchChoices.single({
  Key? key,
  required 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,
  Function? validator,
  bool assertUniqueValue = true,
  Function? displayItem,
  bool dialogBox = true,
  BoxConstraints? menuConstraints,
  bool readOnly = false,
  Color? menuBackgroundColor,
  bool rightToLeft = false,
  bool autofocus = true,
  Function? selectedAggregateWidgetFn,
  double padding = 10.0,
  Function? setOpenDialog,
}) {
  return (SearchChoices._(
    key: key,
    items: items,
    onChanged: onChanged,
    value: value,
    style: style,
    searchHint: searchHint,
    hint: hint,
    disabledHint: disabledHint,
    icon: icon,
    underline: underline,
    iconEnabledColor: iconEnabledColor,
    iconDisabledColor: iconDisabledColor,
    iconSize: iconSize,
    isExpanded: isExpanded,
    isCaseSensitiveSearch: isCaseSensitiveSearch,
    closeButton: closeButton,
    displayClearIcon: displayClearIcon,
    clearIcon: clearIcon,
    onClear: onClear,
    selectedValueWidgetFn: selectedValueWidgetFn,
    keyboardType: keyboardType,
    validator: validator,
    label: label,
    searchFn: searchFn,
    multipleSelection: false,
    doneButton: doneButton,
    displayItem: displayItem,
    dialogBox: dialogBox,
    menuConstraints: menuConstraints,
    readOnly: readOnly,
    menuBackgroundColor: menuBackgroundColor,
    rightToLeft: rightToLeft,
    autofocus: autofocus,
    selectedAggregateWidgetFn: selectedAggregateWidgetFn,
    padding: padding,
    setOpenDialog: setOpenDialog,
  ));
}