DropdownButton<T> class

An interactive select menu button that opens a dropdown list overlay.

Interaction Modes

  • Keyboard: When focused, opens using Space, Enter, or Down Arrow. Once open, navigate choices using Up/Down arrow keys, select using Enter or Space, and close/cancel using Escape.
  • Mouse: Left-clicking opens the menu; clicking an item selects it.

Absolute Portal Mapping

The dropdown uses getAbsoluteRect to resolve its button boundaries within nested viewports, ensuring the floating overlay list maps to absolute screen coordinates directly beneath the button, bypassing child clipping.

Example Usage

DropdownButton<String>(
  value: selectedFruit,
  items: const [
    DropdownMenuItem(value: 'apple', child: Text('Apple')),
    DropdownMenuItem(value: 'banana', child: Text('Banana')),
  ],
  onChanged: (val) {
    setState(() => selectedFruit = val);
  },
);

Properties Table

Property Type Description
items List<DropdownMenuItem> List of options available in the dropdown.
value T? The currently selected value.
onChanged Function(T?) Callback fired when a selection is made.
focused bool Whether this button has keyboard focus.
dropdownStyle Style Style applied to items in the dropdown menu.
Inheritance

Constructors

Creates a new dropdown button.
const

Properties

The style applied to the dropdown menu items.
final
focused bool
Whether the button is currently focused.
final
hashCode int
The hash code for this object.
no setterinherited
hint Widget?
An optional widget to display when no item is selected.
final
items List<DropdownMenuItem<T>>
The list of items to display in the dropdown.
final
key Key?
The optional key for this widget.
finalinherited
onChanged → void Function(T? newValue)?
Callback triggered when a new value is selected.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
style Style
The base style for the dropdown button.
final
value → T?
The currently selected value.
final

Methods

createElement() Element
Creates an Element to manage this widget's location in the tree.
inherited
createState() State<DropdownButton<T>>
Creates the mutable state for this widget at a given location in the tree.
override
getIntrinsicHeight(int width) int
Computes the intrinsic height of this widget under the given width constraint.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
render(Buffer buffer, Rect area) → void
Renders the widget onto the provided buffer within the specified area.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited