FAutocomplete class

An autocomplete provides a list of suggestions based on the user's input and shows typeahead text for the first match.

It is a FormField and therefore can be used in a Form widget.

Note

The autocomplete does not support using arrow keys to navigate the suggestions on web.

See:

Inheritance
Mixed-in types

Constructors

FAutocomplete.new({required List<String> items, FAutocompleteStyle style(FAutocompleteStyle)?, Widget? label, String? hint, Widget? description, TextMagnifierConfiguration? magnifierConfiguration, Object groupId = EditableText, FAutocompleteController? controller, FocusNode? focusNode, TextInputType? keyboardType, TextInputAction? textInputAction, TextCapitalization textCapitalization = TextCapitalization.none, TextAlign textAlign = TextAlign.start, TextAlignVertical? textAlignVertical, TextDirection? textDirection, VoidCallback? onTapHide, bool autofocus = false, WidgetStatesController? statesController, String obscuringCharacter = '•', bool obscureText = false, bool autocorrect = true, SmartDashesType? smartDashesType, SmartQuotesType? smartQuotesType, bool enableSuggestions = true, int? minLines, int? maxLines = 1, bool expands = false, bool readOnly = false, bool? showCursor, int? maxLength, MaxLengthEnforcement? maxLengthEnforcement, ValueChanged<String>? onChange, bool onTapAlwaysCalled = false, VoidCallback? onEditingComplete, ValueChanged<String>? onSubmit, AppPrivateCommandCallback? onAppPrivateCommand, List<TextInputFormatter>? inputFormatters, bool enabled = true, bool? ignorePointers, bool enableInteractiveSelection = true, TextSelectionControls? selectionControls, DragStartBehavior dragStartBehavior = DragStartBehavior.start, MouseCursor? mouseCursor, FTextFieldCounterBuilder? counterBuilder, ScrollPhysics? scrollPhysics, ScrollController? scrollController, Iterable<String>? autofillHints, String? restorationId, bool stylusHandwritingEnabled = true, bool enableIMEPersonalizedLearning = true, ContentInsertionConfiguration? contentInsertionConfiguration, EditableTextContextMenuBuilder? contextMenuBuilder, bool canRequestFocus = true, UndoHistoryController? undoController, SpellCheckConfiguration? spellCheckConfiguration, FFieldIconBuilder<FAutocompleteStyle>? prefixBuilder, FFieldIconBuilder<FAutocompleteStyle>? suffixBuilder, bool clearable(TextEditingValue) = _clearable, FormFieldSetter<String>? onSaved, FormFieldValidator<String>? validator, String? initialText, AutovalidateMode autovalidateMode = AutovalidateMode.disabled, String? forceErrorText, Widget errorBuilder(BuildContext, String) = FFormFieldProperties.defaultErrorBuilder, AlignmentGeometry anchor = AlignmentDirectional.topStart, AlignmentGeometry fieldAnchor = AlignmentDirectional.bottomStart, FPortalConstraints popoverConstraints = const FAutoWidthPortalConstraints(maxHeight: 300), FPortalSpacing spacing = const FPortalSpacing(4), Offset shift(Size, FPortalChildBox, FPortalBox) = FPortalShift.flip, Offset offset = Offset.zero, FPopoverHideRegion hideRegion = FPopoverHideRegion.excludeChild, bool autoHide = true, FFieldBuilder<FAutocompleteStyle> builder = _builder, bool rightArrowToComplete = false, FutureOr<Iterable<String>> filter(String)?, FAutoCompleteContentBuilder? contentBuilder, ScrollController? contentScrollController, ScrollPhysics contentPhysics = const ClampingScrollPhysics(), FItemDivider contentDivider = FItemDivider.none, Widget contentEmptyBuilder(BuildContext, FAutocompleteContentStyle) = defaultContentEmptyBuilder, Widget contentLoadingBuilder(BuildContext, FAutocompleteContentStyle) = defaultContentLoadingBuilder, Widget contentErrorBuilder(BuildContext, Object?, StackTrace)?, Key? key})
Creates a FAutocomplete from the given items.
FAutocomplete.builder({required FutureOr<Iterable<String>> filter(String text), required FAutoCompleteContentBuilder contentBuilder, FAutocompleteStyle style(FAutocompleteStyle)?, Widget? label, String? hint, Widget? description, TextMagnifierConfiguration? magnifierConfiguration, Object groupId = EditableText, FAutocompleteController? controller, FocusNode? focusNode, TextInputType? keyboardType, TextInputAction? textInputAction, TextCapitalization textCapitalization = TextCapitalization.none, TextAlign textAlign = TextAlign.start, TextAlignVertical? textAlignVertical, TextDirection? textDirection, VoidCallback? onTapHide, bool autofocus = false, WidgetStatesController? statesController, String obscuringCharacter = '•', bool obscureText = false, bool autocorrect = true, SmartDashesType? smartDashesType, SmartQuotesType? smartQuotesType, bool enableSuggestions = true, int? minLines, int? maxLines = 1, bool expands = false, bool readOnly = false, bool? showCursor, int? maxLength, MaxLengthEnforcement? maxLengthEnforcement, ValueChanged<String>? onChange, bool onTapAlwaysCalled = false, VoidCallback? onEditingComplete, ValueChanged<String>? onSubmit, AppPrivateCommandCallback? onAppPrivateCommand, List<TextInputFormatter>? inputFormatters, bool enabled = true, bool? ignorePointers, bool enableInteractiveSelection = true, TextSelectionControls? selectionControls, DragStartBehavior dragStartBehavior = DragStartBehavior.start, MouseCursor? mouseCursor, FTextFieldCounterBuilder? counterBuilder, ScrollPhysics? scrollPhysics, ScrollController? scrollController, Iterable<String>? autofillHints, String? restorationId, bool stylusHandwritingEnabled = true, bool enableIMEPersonalizedLearning = true, ContentInsertionConfiguration? contentInsertionConfiguration, EditableTextContextMenuBuilder? contextMenuBuilder, bool canRequestFocus = true, UndoHistoryController? undoController, SpellCheckConfiguration? spellCheckConfiguration, FFieldIconBuilder<FAutocompleteStyle>? prefixBuilder, FFieldIconBuilder<FAutocompleteStyle>? suffixBuilder, bool clearable(TextEditingValue) = _clearable, FormFieldSetter<String>? onSaved, FormFieldValidator<String>? validator, String? initialText, AutovalidateMode autovalidateMode = AutovalidateMode.disabled, String? forceErrorText, Widget errorBuilder(BuildContext, String) = FFormFieldProperties.defaultErrorBuilder, AlignmentGeometry anchor = AlignmentDirectional.topStart, AlignmentGeometry fieldAnchor = AlignmentDirectional.bottomStart, FPortalConstraints popoverConstraints = const FAutoWidthPortalConstraints(maxHeight: 300), FPortalSpacing spacing = const FPortalSpacing(4), Offset shift(Size, FPortalChildBox, FPortalBox) = FPortalShift.flip, Offset offset = Offset.zero, FPopoverHideRegion hideRegion = FPopoverHideRegion.excludeChild, bool autoHide = true, FFieldBuilder<FAutocompleteStyle> builder = _builder, bool rightArrowToComplete = false, ScrollController? contentScrollController, ScrollPhysics contentPhysics = const ClampingScrollPhysics(), FItemDivider contentDivider = FItemDivider.none, Widget contentEmptyBuilder(BuildContext, FAutocompleteContentStyle) = defaultContentEmptyBuilder, Widget contentLoadingBuilder(BuildContext, FAutocompleteContentStyle) = defaultContentLoadingBuilder, Widget contentErrorBuilder(BuildContext, Object?, StackTrace)?, Key? key})
Creates a FAutocomplete that uses the given filter to determine the results and the contentBuilder to build the content.
const

Properties

anchor AlignmentGeometry
The alignment point on the popover. Defaults to AlignmentDirectional.topStart.
final
autocorrect bool
Whether to enable autocorrection. Defaults to true.
final
autofillHints Iterable<String>?
A list of strings that helps the autofill service identify the type of this text input.
final
autofocus bool
Whether this text field should focus itself if nothing else is already focused. Defaults to false.
final
autoHide bool
True if the select should be automatically hidden after an item is selected. Defaults to false.
final
autovalidateMode AutovalidateMode
Used to enable/disable this form field's auto validation and update its error text.
final
builder FFieldBuilder<FAutocompleteStyle>
The builder used to decorate the autocomplete. It should always use the given child.
final
canRequestFocus bool
Determine whether this text field can request the primary focus.
final
clearable bool Function(TextEditingValue)
A predicate that returns true if a clear icon should be shown at the end when the text field is not empty.
final
contentBuilder FAutoCompleteContentBuilder
A callback builds the list of items based on search results returned by filter.
final
contentDivider FItemDivider
The divider used to separate the content items. Defaults to FItemDivider.none.
final
contentEmptyBuilder Widget Function(BuildContext, FAutocompleteContentStyle)
The builder that is called when the select is empty. Defaults to defaultContentEmptyBuilder.
final
contentErrorBuilder Widget Function(BuildContext, Object?, StackTrace)?
A callback that is used to show an error message when filter is asynchronous and fails.
final
contentInsertionConfiguration ContentInsertionConfiguration?
Configuration of handler for media content inserted via the system input method.
final
contentLoadingBuilder Widget Function(BuildContext, FAutocompleteContentStyle)
A callback that is used to show a loading indicator while the results is processed.
final
contentPhysics ScrollPhysics
The content's scroll physics. Defaults to ClampingScrollPhysics.
final
contentScrollController ScrollController?
The content's scroll controller.
final
contextMenuBuilder EditableTextContextMenuBuilder?
Builds the text selection toolbar when requested by the user.
final
controller FAutocompleteController?
The controller.
final
counterBuilder FTextFieldCounterBuilder?
The FTextFieldCounterBuilder used to build a custom counter for the text field.
final
description Widget?
The description text.
final
dragStartBehavior DragStartBehavior
Determines the way that drag start behavior is handled. By default, the drag start behavior is DragStartBehavior.start.
final
enabled bool
If false the text field is "disabled": it ignores taps. Defaults to true.
final
enableIMEPersonalizedLearning bool
Whether to enable that the IME update personalized data such as typing history and user dictionary data.
final
enableInteractiveSelection bool
Whether to enable user interface affordances for changing the text selection. Defaults to true.
final
enableSuggestions bool
Whether to show input suggestions as the user types. Defaults to true.
final
errorBuilder Widget Function(BuildContext, String)
The builder for errors displayed below the description. Defaults to displaying the error message.
final
expands bool
Whether this widget's height will be sized to fill its widget. Defaults to false.
final
fieldAnchor AlignmentGeometry
The alignment point on the select's field. Defaults to AlignmentDirectional.bottomStart.
final
filter FutureOr<Iterable<String>> Function(String text)
A callback that produces a list of items based on the query either synchronously or asynchronously.
final
focusNode FocusNode?
Defines the keyboard focus for this FTextField.
final
forceErrorText String?
An optional property that forces the FormFieldState into an error state by directly setting the FormFieldState.errorText property without running the validator function.
final
groupId Object
The group identifier for the TextFieldTapRegion of this text field.
final
hashCode int
The hash code for this object.
no setterinherited
hideRegion FPopoverHideRegion
The region that can be tapped to hide the popover.
final
hint String?
The text to display when the text field is empty.
final
ignorePointers bool?
Determines whether this widget ignores pointer events. Defaults to null, and when null, does nothing.
final
initialText String?
The initial text.
final
inputFormatters List<TextInputFormatter>?
Optional input validation and formatting overrides.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
keyboardType TextInputType?
The type of keyboard to use for editing the text. Defaults to TextInputType.text if maxLines is one and TextInputType.multiline otherwise.
final
label Widget?
A builder that creates a widget to display validation errors.
final
magnifierConfiguration TextMagnifierConfiguration?
The configuration for the magnifier of this text field.
final
maxLength int?
The maximum number of characters (Unicode grapheme clusters) to allow in the text field.
final
maxLengthEnforcement MaxLengthEnforcement?
Determines how the maxLength limit should be enforced.
final
maxLines int?
The maximum number of lines to show at one time, wrapping if necessary.
final
minLines int?
The minimum number of lines to occupy when the content spans fewer lines.
final
mouseCursor MouseCursor?
The cursor for a mouse pointer when it enters or is hovering over the widget.
final
obscureText bool
Whether to hide the text being edited (e.g., for passwords). Defaults to false.
final
obscuringCharacter String
Character used for obscuring text if obscureText is true.
final
offset Offset
The offset to adjust the popover by. Defaults to Offset.zero.
final
onAppPrivateCommand AppPrivateCommandCallback?
This is used to receive a private command from the input method.
final
onChange ValueChanged<String>?
Called when the user initiates a change to the TextField's value: when they have inserted or deleted text.
final
onEditingComplete VoidCallback?
Called when the user submits editable content (e.g., user presses the "done" button on the keyboard).
final
onSaved FormFieldSetter<String>?
An optional method to call with the final value when the form is saved via FormState.save.
final
onSubmit ValueChanged<String>?
Called when the user indicates that they are done editing the text in the field.
final
onTapAlwaysCalled bool
Called for the first tap in a series of taps.
final
onTapHide VoidCallback?
A callback that is called when the popover is hidden by tapping outside of it.
final
popoverConstraints FPortalConstraints
The constraints to apply to the popover. Defaults to const FAutoWidthPortalConstraints(maxHeight: 300).
final
prefixBuilder FFieldIconBuilder<FAutocompleteStyle>?
The prefix's builder.
final
readOnly bool
Whether the text can be changed. Defaults to false.
final
restorationId String?
Restoration ID to save and restore the state of the text field.
final
rightArrowToComplete bool
Whether the autocomplete should complete the text when a completion is available and the user presses right arrow. Defaults to false.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scrollController ScrollController?
The ScrollController to use when vertically scrolling the input. If null, it will instantiate a new ScrollController.
final
scrollPhysics ScrollPhysics?
The ScrollPhysics to use when vertically scrolling the input. If not specified, it will behave according to the current platform.
final
selectionControls TextSelectionControls?
Optional delegate for building the text selection handles.
final
shift Offset Function(Size, FPortalChildBox, FPortalBox)
The shifting strategy used to shift a popover when it overflows out of the viewport. Defaults to FPortalShift.flip.
final
showCursor bool?
Whether to show cursor.
final
smartDashesType SmartDashesType?
Whether to allow the platform to automatically format dashes.
final
smartQuotesType SmartQuotesType?
Whether to allow the platform to automatically format quotes.
final
spacing FPortalSpacing
The spacing between the child's anchor and popover's anchor. Defaults to FPortalSpacing(4).
final
spellCheckConfiguration SpellCheckConfiguration?
Configuration that details how spell check should be performed.
final
statesController WidgetStatesController?
Represents the interactive "state" of this widget in terms of a set of WidgetStates, including WidgetState.disabled, WidgetState.hovered, WidgetState.error, and WidgetState.focused.
final
style FAutocompleteStyle Function(FAutocompleteStyle)?
The style.
final
stylusHandwritingEnabled bool
Whether this input supports stylus handwriting, where the user can write directly on top of a field.
final
suffixBuilder FFieldIconBuilder<FAutocompleteStyle>?
The suffix's builder.
final
textAlign TextAlign
How the text should be aligned horizontally.
final
textAlignVertical TextAlignVertical?
How the text should be aligned vertically.
final
textCapitalization TextCapitalization
Configures how the platform keyboard will select an uppercase or lowercase keyboard. Defaults to TextCapitalization.none.
final
textDirection TextDirection?
The directionality of the text. Defaults to the ambient Directionality, if any.
final
textInputAction TextInputAction?
The type of action button to use for the keyboard.
final
undoController UndoHistoryController?
Controls the undo state.
final
validator FormFieldValidator<String>?
An optional method that validates an input. Returns an error string to display if the input is invalid, or null otherwise.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<FAutocomplete>
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.
override
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

Static Methods

defaultContentEmptyBuilder(BuildContext context, FAutocompleteContentStyle style) Widget
The default empty builder that shows a localized message when there are no results.
defaultContentLoadingBuilder(BuildContext _, FAutocompleteContentStyle style) Widget
The default loading builder that shows a spinner when an asynchronous search is pending.