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, bool autofocus = false, AutovalidateMode? autovalidateMode, TextEditingController? controller, Widget emptyWidget = const SizedBox(), bool? enabled, FocusNode? focusNode, String? hint, SearchFieldListItem<T> >T> ? initialValue, List<TextInputFormatter> ? inputFormatters, TextInputType? inputType, double itemHeight = 35.0, Color? marginColor, int maxSuggestionsInViewPort = 5, bool readOnly = false, List<SearchFieldListItem< ? onSearchTextChanged(String)?, void onSaved(String?)?, void onScroll(double, double)?, void onTap()?, dynamic onSubmit(String)?, void onTapOutside(PointerDownEvent)?, Offset? offset, dynamic onSuggestionTap(SearchFieldListItem<T> >T> )?, InputDecoration? searchInputDecoration, TextStyle? searchStyle, ScrollbarDecoration? scrollbarDecoration, bool showEmpty = false, TextStyle? suggestionStyle, SuggestionDecoration? suggestionsDecoration, SuggestionDirection suggestionDirection = SuggestionDirection.down, Suggestion suggestionState = Suggestion.expand, BoxDecoration? suggestionItemDecoration, SuggestionAction? suggestionAction, TextAlign textAlign = TextAlign.start, TextCapitalization textCapitalization = TextCapitalization.none, TextInputAction? textInputAction, String? validator(String?)?})
Properties
- animationDuration → Duration
-
duration of the suggestion list animation
final
- autoCorrect → bool
-
Defines whether to enable autoCorrect defaults to
true
final - autofocus → bool
-
Defines whether to enable autofocus defaults to
false
final - 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
- controller → TextEditingController?
-
Specifies the
TextEditingController
for SearchField.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
true
final - 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
-
initialValue
→ SearchFieldListItem<
T> ? -
The initial value to be selected for SearchField. The value
must be present in suggestions.
final
-
inputFormatters
→ List<
TextInputFormatter> ? -
input formatter for the searchfield
final
- inputType → TextInputType?
-
Keyboard Type for SearchField
final
- itemHeight → double
-
Specifies height for each suggestion item in the list.
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
- 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 position in pixels and the maximum scroll extent
of the suggestions list. The callback can be used to implement feature like
lazy loading of suggestions.
see example in example/lib/pagination
final
-
onSearchTextChanged
→ (List<
SearchFieldListItem< ? Function(String)?)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
SearchFieldListItem
insuggestions
will 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
- searchInputDecoration → InputDecoration?
-
Specifies InputDecoration for search input TextField.
final
- searchStyle → TextStyle?
-
Specifies TextStyle for search input.
final
- showEmpty → bool
-
final
- suggestionAction → SuggestionAction?
-
Specifies the SuggestionAction called on suggestion tap.
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
- textCapitalization → TextCapitalization
-
text capitalization defaults to TextCapitalization.none
final
- textInputAction → TextInputAction?
-
Define a TextInputAction that is called when the field is submitted
final
- validator → (String? Function(String?)?)
-
validator
for 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}) → 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