SearchField<T> class
A widget that displays a searchfield and a list of suggestions
when the searchfield is brought into focus
see example/lib/country_search.dart
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- SearchField
Constructors
-
SearchField({Key? key, required List<
SearchFieldListItem< suggestions, Duration animationDuration = const Duration(milliseconds: 300), bool autoCorrect = true, ScrollController? scrollController, bool autofocus = false, AutovalidateMode? autovalidateMode, Widget contextMenuBuilder(BuildContext, EditableTextState)?, TextEditingController? controller, Widget emptyWidget = const SizedBox(), bool? enabled, FocusNode? focusNode, @Deprecated('Use SearchInputDecoration.hintText instead.') String? hint, SearchFieldListItem<T> >T> ? selectedValue, List<TextInputFormatter> ? inputFormatters, TextInputType? inputType, bool keepSearchOnSelection = false, bool dynamicHeight = false, double? maxSuggestionBoxHeight, double itemHeight = 51.0, Color? marginColor, int maxSuggestionsInViewPort = 5, int? maxLength, MaxLengthEnforcement? maxLengthEnforcement, InputCounterWidgetBuilder? buildCounter, bool readOnly = false, FutureOr<List< ? onSearchTextChanged(String)?, void onSaved(String?)?, void onScroll(double, double)?, void onTap()?, dynamic onSubmit(String)?, void onTapOutside(PointerDownEvent)?, Offset? offset, dynamic onSuggestionTap(SearchFieldListItem<SearchFieldListItem< >T> >T> )?, SearchInputDecoration? searchInputDecoration, ScrollbarDecoration? scrollbarDecoration, bool showEmpty = false, TextStyle? suggestionStyle, SuggestionDecoration? suggestionsDecoration, SuggestionDirection suggestionDirection = SuggestionDirection.down, Suggestion suggestionState = Suggestion.expand, BoxDecoration? suggestionItemDecoration, SuggestionAction? suggestionAction = SuggestionAction.unfocus, TextAlign textAlign = TextAlign.start, TextInputAction? textInputAction, String? validator(String?)?})
Properties
- animationDuration → Duration
-
duration of the suggestion list animation
final
- autoCorrect → bool
-
Defines whether to enable autoCorrect defaults to
truefinal - autofocus → bool
-
Defines whether to enable autofocus defaults to
falsefinal - autovalidateMode → AutovalidateMode?
-
Used to enable/disable this form field auto validation and update its error text.
If AutovalidateMode.onUserInteraction, this FormField will only auto-validate after its
content changes. If AutovalidateMode.always, it will auto-validate even without user
interaction. If AutovalidateMode.disabled, auto-validation will be disabled.
final
- buildCounter → InputCounterWidgetBuilder?
-
If buildCounter returns null, then no counter and no Semantics widget will
be created at all.
final
- contextMenuBuilder ↔ Widget Function(BuildContext, EditableTextState)?
-
Creates a FormField that contains a TextField.
getter/setter pair
- controller → TextEditingController?
-
Specifies the
TextEditingControllerfor SearchField. The client is responsible for creating and disposing of the controller. If a controller is not specified, a new one will be created and disposed of internally.final - dynamicHeight → bool
-
Set to true to opt-in to dynamic height. We don't calculate the total height for the whole box, instead, each item on the suggestion list will have their respective height.
final
- emptyWidget → Widget
-
Widget to show when the search returns
empty results or when showEmpty: true.
defaults to SizedBox.shrink
final
- enabled → bool?
-
Defines whether to enable the searchfield defaults to
truefinal - focusNode → FocusNode?
-
focus node for the searchfield
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- hint → String?
-
Hint for the SearchField.
final
-
inputFormatters
→ List<
TextInputFormatter> ? -
input formatter for the searchfield
final
- inputType → TextInputType?
-
Keyboard Type for SearchField defaults to TextInputType.text
final
- itemHeight → double
-
Specifies height for each suggestion item in the list.
final
- keepSearchOnSelection → bool
-
keep search text on selection
defaults to false
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- marginColor → Color?
-
Specifies the color of margin between items in suggestions list.
final
- maxLength → int?
-
Defines character limit for searchfield
final
- maxLengthEnforcement → MaxLengthEnforcement?
-
Defines mechanisms for enforcing maximum length limits
final
- maxSuggestionBoxHeight → double?
-
(Optional) Specifies a maximum height for the suggestion box.
final
- maxSuggestionsInViewPort → int
-
Specifies the number of suggestions that can be shown in viewport.
final
- offset → Offset?
-
suggestion List offset from the searchfield
The top left corner of the searchfield is the origin (0,0)
final
- onSaved → void Function(String?)?
-
An optional method to call with the final value when the form is saved via FormState.save.
final
- onScroll → void Function(double, double)?
-
Callback when the suggestions are scrolled
The callback returns the
current scroll positionin pixels and themaximum scroll extentof the suggestions list. The callback can be used to implement feature like lazy loading of suggestions. see example in example/lib/pagination to see it in actionfinal -
onSearchTextChanged
→ FutureOr<
List< ? Function(String)?SearchFieldListItem< >T> > -
Callback when the searchfield is searched.
The callback should return a list of SearchFieldListItem based on custom logic which will be
shown as suggestions.
If the callback is not specified, the searchfield will show suggestions which contains the
search text.
final
- onSubmit → dynamic Function(String)?
-
Callback when the Searchfield is submitted by pressing
the enter key on the keyboard
This callback returns the text from the searchfield
final
-
onSuggestionTap
→ dynamic Function(SearchFieldListItem<
T> )? -
Callback when the suggestion is selected.
The parameters passed to
SearchFieldListIteminsuggestionswill be returned in the callback.final - onTap → void Function()?
-
Callback when the searchfield is tapped
or brought into focus
final
- onTapOutside → void Function(PointerDownEvent)?
-
Callback when a tap is performed outside Searchfield (during the time the field has focus)
final
- readOnly → bool
-
Defines whether to show the searchfield as readOnly
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scrollbarDecoration → ScrollbarDecoration?
-
final
- scrollController → ScrollController?
-
Scroll Controller for the suggestion list
final
- searchInputDecoration ↔ SearchInputDecoration?
-
Specifies InputDecoration for search input TextField.
getter/setter pair
-
selectedValue
→ SearchFieldListItem<
T> ? -
The value to be selected for SearchField. The value
must be present in suggestions.
final
- showEmpty → bool
-
final
- suggestionAction → SuggestionAction?
-
Specifies the SuggestionAction called on suggestion tap defaults to SuggestionAction.unfocus
final
- suggestionDirection → SuggestionDirection
-
suggestion direction defaults to SuggestionDirection.down
final
- suggestionItemDecoration → BoxDecoration?
-
Specifies BoxDecoration for items in suggestion list. The property can be used to add BoxShadow,
and much more. For more information, checkout BoxDecoration.
final
-
suggestions
→ List<
SearchFieldListItem< T> > -
List of suggestions for the searchfield.
each suggestion should have a unique searchKey
final
- suggestionsDecoration → SuggestionDecoration?
-
Specifies SuggestionDecoration for suggestion list. The property can be used to add BoxShadow, BoxBorder
and much more. For more information, checkout BoxDecoration.
final
- suggestionState → Suggestion
-
defaults to SuggestionState.expand
final
- suggestionStyle → TextStyle?
-
Specifies TextStyle for suggestions when no child is provided
in SearchFieldListItem.
final
- textAlign → TextAlign
-
alignment of the text in the searchfield
defaults to TextAlign.start
final
- textInputAction → TextInputAction?
-
Define a TextInputAction that is called when the field is submitted
final
- validator → String? Function(String?)?
-
validatorfor the SearchField to make use of this validator, The SearchField widget needs to be wrapped in a Form and pass it a Global key and write your validation logic in the validator you can define a global keyfinal
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → _SearchFieldState< 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, int wrapWidth = 65}) → 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