Dropdown<T> class

A dropdown menu that can be opened from a TextField. The selected menu item is displayed in that field.

This widget is used to help people make a choice from a menu and put the selected item into the text input field. People can also filter the list based on the text input or search one item in the menu list.

The menu is composed of a list of DropdownMenuEntrys. People can provide information, such as: label, leading icon or trailing icon for each entry. The TextField will be updated based on the selection from the menu entries. The text field will stay empty if the selected entry is disabled.

The dropdown menu can be traversed by pressing the up or down key. During the process, the corresponding item will be highlighted and the text field will be updated. Disabled items will be skipped during traversal.

The menu can be scrollable if not all items in the list are displayed at once.

{@tool dartpad} This sample shows how to display outlined DropdownMenu and filled DropdownMenu.

** See code in examples/api/lib/material/dropdown_menu/dropdown_menu.0.dart ** {@end-tool}

See also:

Inheritance

Constructors

Creates a const DropdownMenu.
const

Properties

controller DropdownTextController?
Controls the text being edited or selected in the menu.
final
Descriptions of the menu items in the DropdownMenu.
final
enabled bool
Determine if the DropdownMenu is enabled.
final
enableFilter bool
Determine if the menu list can be filtered by the text input.
final
enableSearch bool
Determine if the first item that matches the text input can be highlighted.
final
errorText String?
Text that appears below the input field and the border to show the error message.
final
expandedInsets EdgeInsets?
Defines the menu text field's width to be equal to its parent's width plus the horizontal width of the specified insets.
final
filterCallback FilterCallback<T>?
When DropdownMenu.enableFilter is true, this callback is used to compute the list of filtered items.
final
focusNode FocusNode?
Defines the keyboard focus for this widget.
final
hashCode int
The hash code for this object.
no setterinherited
helperText String?
Text that provides context about the DropdownMenu's value, such as how the value will be used.
final
hintText String?
Text that suggests what sort of input the field accepts.
final
initialSelection → T?
The value used to for an initial selection.
final
inputDecorationTheme InputDecorationTheme?
Defines the default appearance of InputDecoration to show around the text field.
final
inputFormatters List<TextInputFormatter>?
Optional input validation and formatting overrides.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
label Widget?
Optional widget that describes the input field.
final
leadingIcon Widget?
An optional Icon at the front of the text input field.
final
Determine the height of the menu.
final
The MenuStyle that defines the visual attributes of the menu.
final
onSelected ValueChanged<T?>?
The callback is called when a selection is made.
final
requestFocusOnTap bool?
Determine if the dropdown button requests focus and the on-screen virtual keyboard is shown in response to a touch event.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
searchCallback SearchCallback<T>?
When DropdownMenu.enableSearch is true, this callback is used to compute the index of the search result to be highlighted.
final
selectedTrailingIcon Widget?
An optional icon at the end of the text field to indicate that the text field is pressed.
final
textAlign TextAlign
The text align for the TextField of the DropdownMenu.
final
textStyle TextStyle?
The text style for the TextField of the DropdownMenu;
final
trailingIcon Widget?
An optional icon at the end of the text field.
final
width double?
Determine the width of the DropdownMenu.
final

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
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