getSearchbar method
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 dynamic onChangeMethod(),
- required dynamic onSubmitMethod(),
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);
},
);
}