MacosSearchField<T> constructor

const MacosSearchField<T>({
  1. Key? key,
  2. List<SearchResultItem>? results,
  3. dynamic onResultSelected(
    1. SearchResultItem
    )?,
  4. int maxResultsToShow = 5,
  5. double resultHeight = _kResultHeight,
  6. Widget emptyWidget = const SizedBox.shrink(),
  7. TextEditingController? controller,
  8. FocusNode? focusNode,
  9. BoxDecoration? decoration = kDefaultRoundedBorderDecoration,
  10. BoxDecoration? focusedDecoration = kDefaultFocusedBorderDecoration,
  11. EdgeInsets padding = const EdgeInsets.all(4.0),
  12. String? placeholder = "Search",
  13. TextStyle? placeholderStyle = const TextStyle(fontWeight: FontWeight.w400, color: CupertinoColors.placeholderText),
  14. TextStyle? style,
  15. TextAlign textAlign = TextAlign.start,
  16. bool autocorrect = true,
  17. bool autofocus = false,
  18. int? maxLines,
  19. int? minLines,
  20. bool expands = false,
  21. int? maxLength,
  22. MaxLengthEnforcement? maxLengthEnforcement,
  23. ValueChanged<String>? onChanged,
  24. List<TextInputFormatter>? inputFormatters,
  25. bool? enabled = true,
  26. GestureTapCallback? onTap,
})

Creates a macOS-style search field.

To provide a prefilled text entry, pass in a TextEditingController with an initial value to the controller parameter.

To provide a hint placeholder text that appears when the text entry is empty, pass a String to the placeholder parameter.

Based on a MacosTextField widget.

When focused or tapped, it opens an overlay showing a results list of SearchResultItems to choose from.

If searching yields no results, the emptyWidget is shown instead (set by default to SizedBox.shrink).

Set what happens when selecting a suggestion item via the onResultSelected property.

You can also set a callback action individually for each SearchResultItem via the onSelected property.

Implementation

const MacosSearchField({
  super.key,
  this.results,
  this.onResultSelected,
  this.maxResultsToShow = 5,
  this.resultHeight = _kResultHeight,
  this.emptyWidget = const SizedBox.shrink(),
  this.controller,
  this.focusNode,
  this.decoration = kDefaultRoundedBorderDecoration,
  this.focusedDecoration = kDefaultFocusedBorderDecoration,
  this.padding = const EdgeInsets.all(4.0),
  this.placeholder = "Search",
  this.placeholderStyle = const TextStyle(
    fontWeight: FontWeight.w400,
    color: CupertinoColors.placeholderText,
  ),
  this.style,
  this.textAlign = TextAlign.start,
  this.autocorrect = true,
  this.autofocus = false,
  this.maxLines,
  this.minLines,
  this.expands = false,
  this.maxLength,
  this.maxLengthEnforcement,
  this.onChanged,
  this.inputFormatters,
  this.enabled = true,
  this.onTap,
});