DropdownMenu<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.
When the dropdown menu has focus, it 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.
To create a local project with this code sample, run:
flutter create --sample=material.DropdownMenu.1 mysample
See also:
- MenuAnchor, which is a widget used to mark the "anchor" for a set of submenus. The DropdownMenu uses a TextField as the "anchor".
- TextField, which is a text input widget that uses an InputDecoration.
- DropdownMenuEntry, which is used to build the MenuItemButton in the DropdownMenu list.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- DropdownMenu
Constructors
-
DropdownMenu({Key? key, bool enabled = true, double? width, Widget? leadingIcon, Widget? trailingIcon, Widget? label, String? hintText, String? helperText, String? errorText, Widget? selectedTrailingIcon, bool enableFilter = false, bool enableSearch = true, TextInputType? keyboardType, TextStyle? textStyle, TextAlign textAlign = TextAlign.start, InputDecorationTheme? inputDecorationTheme, TextEditingController? controller, T? initialSelection, ValueChanged<
T?> ? onSelected, FocusNode? focusNode, bool? requestFocusOnTap, EdgeInsetsGeometry? expandedInsets, FilterCallback<T> ? filterCallback, SearchCallback<T> ? searchCallback, Offset? alignmentOffset, required List<DropdownMenuEntry< dropdownMenuEntries, List<T> >TextInputFormatter> ? inputFormatters}) -
Creates a const DropdownMenu.
const
Properties
- alignmentOffset → Offset?
-
The offset of the menu relative to the alignment origin determined by
MenuStyle.alignment on the
style
attribute and the ambient Directionality.final - controller → TextEditingController?
-
Controls the text being edited or selected in the menu.
final
-
dropdownMenuEntries
→ List<
DropdownMenuEntry< T> > -
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 → EdgeInsetsGeometry?
-
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
- keyboardType → TextInputType?
-
The type of keyboard to use for editing the text.
final
- 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
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< DropdownMenu< 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