RawAutocomplete class - widgets library

RawAutocomplete<T extends Object> class

A widget for helping the user make a selection by entering some text and choosing from among a list of options.

The user's text input is received in a field built with the fieldViewBuilder parameter. The options to be displayed are determined using optionsBuilder and rendered with optionsViewBuilder.

The options view opens when the field gains focus or when the field's text changes, as long as optionsBuilder returns at least one option. The options view closes when the user selects an option, when there are no matching options, or when the field loses focus.

This is a core framework widget with very basic UI.

link

To create a local project with this code sample, run:
flutter create --sample=widgets.RawAutocomplete.1 mysample

The type parameter T represents the type of the options. Most commonly this is a String, as in the example above. However, it's also possible to use another type with a toString method, or a custom displayStringForOption. Options will be compared using ==, so it may be beneficial to override Object.== and Object.hashCode for custom types.

This example is similar to the previous example, but it uses a custom T data type instead of directly using String.

link

To create a local project with this code sample, run:
flutter create --sample=widgets.RawAutocomplete.2 mysample

This example shows the use of RawAutocomplete in a form.

link

To create a local project with this code sample, run:
flutter create --sample=widgets.RawAutocomplete.3 mysample

See also:

  • Autocomplete, which is a Material-styled implementation that is based on RawAutocomplete.
Inheritance

Constructors

RawAutocomplete({Key? key, required AutocompleteOptionsViewBuilder<T> optionsViewBuilder, required AutocompleteOptionsBuilder<T> optionsBuilder, OptionsViewOpenDirection optionsViewOpenDirection = OptionsViewOpenDirection.down, AutocompleteOptionToString<T> displayStringForOption = defaultStringForOption, AutocompleteFieldViewBuilder? fieldViewBuilder, FocusNode? focusNode, AutocompleteOnSelected<T>? onSelected, TextEditingController? textEditingController, TextEditingValue? initialValue})
Create an instance of RawAutocomplete.

const

Properties

displayStringForOption AutocompleteOptionToString<T>
Returns the string to display in the field when the option is selected.

final

fieldViewBuilder AutocompleteFieldViewBuilder?
Builds the field whose input is used to get the options.

final

focusNode FocusNode?
The FocusNode that is used for the text field.

final

hashCode int
The hash code for this object.

no setterinherited

initialValue TextEditingValue?
The initial value to use for the text field.

final

key Key?
Controls how one widget replaces another widget in the tree.

finalinherited

onSelected AutocompleteOnSelected<T>?
Called when an option is selected by the user.

final

optionsBuilder AutocompleteOptionsBuilder<T>
A function that returns the current selectable options objects given the current TextEditingValue.

final

optionsViewBuilder AutocompleteOptionsViewBuilder<T>
Builds the selectable options widgets from a list of options objects.

final

optionsViewOpenDirection OptionsViewOpenDirection
Determines the direction in which to open the options view.

final

runtimeType Type
A representation of the runtime type of the object.

no setterinherited

textEditingController TextEditingController?
The TextEditingController that is used for the text field.

final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.

inherited

createState() State<RawAutocomplete<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

Static Methods

defaultStringForOption(Object? option) String
The default way to convert an option to a string in displayStringForOption.
onFieldSubmitted<T extends Object>(GlobalKey<State<StatefulWidget>> key) → void
Calls AutocompleteFieldViewBuilder's onFieldSubmitted callback for the RawAutocomplete widget indicated by the given GlobalKey.