getSearchbar method

Widget getSearchbar({
  1. FocusNode? focusNode,
  2. TextEditingController? textEditorController,
  3. String searchHint = "",
  4. int maxLines = 1,
  5. double leftPadding = 0,
  6. double rightPadding = 0,
  7. bool isShowPrefixIcon = true,
  8. TextInputType textInputType = TextInputType.text,
  9. required dynamic onChangeMethod(
    1. String
    ),
  10. required dynamic onSubmitMethod(
    1. String
    ),
})

Creates a customizable search bar widget.

Provides a text field optimized for search functionality with prefix icon support, keyboard actions, and both onChange and onSubmit callbacks.

Parameters:

  • focusNode: Optional FocusNode for managing focus state.
  • textEditorController: Controller for the text field.
  • searchHint: Placeholder text for the search field.
  • maxLines: Maximum number of lines (defaults to 1).
  • leftPadding: Left padding of the text field (defaults to 0).
  • rightPadding: Right padding of the text field (defaults to 0).
  • isShowPrefixIcon: Whether to show the prefix search icon (defaults to true).
  • textInputType: Keyboard type (defaults to TextInputType.text).
  • onChangeMethod: Callback invoked when the text changes.
  • onSubmitMethod: Callback invoked when the search is submitted.

Returns a DefaultTextField configured for search.

Example:

getSearchbar(
  textEditorController: searchController,
  searchHint: 'Search users...',
  onChangeMethod: (value) => performSearch(value),
  onSubmitMethod: (value) => executeSearch(value),
);

Implementation

Widget getSearchbar(
    {FocusNode? focusNode,
    TextEditingController? textEditorController,
    String searchHint = "",
    int maxLines = 1,
    double leftPadding = 0,
    double rightPadding = 0,
    bool isShowPrefixIcon = true,
    TextInputType textInputType = TextInputType.text,
    required Function(String) onChangeMethod,
    required Function(String) onSubmitMethod}) {
  return DefaultTextField(
    leftPadding: leftPadding,
    rightPadding: rightPadding,
    hintText: searchHint,
    maxLines: maxLines,
    keyboardType: textInputType,
    focusValue: focusNode,
    mainController: textEditorController,
    onChanged: (value) => onChangeMethod(value),
    inputAction: TextInputAction.search,
    isShowPrefixIcon: isShowPrefixIcon,
    onSubmitted: (value) {
      onSubmitMethod(value);
    },
  );
}