PopupMenuButton<T> class
A button that displays a pop-up option menu when triggered.
Unlike a dropdown, a popup menu is typically used for general action items.
Interaction Modes
- Keyboard: Open via Space/Enter/Down. Navigate with Up/Down keys, execute selected action with Enter/Space, and cancel using Escape.
- Mouse: Click to open, click an item to trigger selection.
Absolute Portal Mapping
Resolves its relative layout position via getAbsoluteRect to project a menu panel onto the root Overlay directly below the trigger child.
Example Usage
PopupMenuButton<String>(
items: const [
PopupMenuItem(value: 'edit', child: Text('Edit')),
PopupMenuItem(value: 'delete', child: Text('Delete')),
],
onSelected: (action) {
print('Action chosen: $action');
},
onCanceled: () {
print('Menu closed without action.');
},
child: Text('Options'),
);
Properties Table
| Property | Type | Description |
|---|---|---|
items |
List<PopupMenuItem> | List of action choices. |
onSelected |
Function(T) |
Callback triggered when an item is selected. |
onCanceled |
Function() |
Callback triggered when closed via Escape. |
child |
Widget | The trigger widget displaying on the screen. |
dropdownStyle |
Style | The selection hover style in the menu. |
- Inheritance
-
- Object
- Widget
- StatefulWidget
- PopupMenuButton
- Implemented types
Constructors
-
PopupMenuButton({required List<
PopupMenuItem< items, void onSelected(T value)?, void onCanceled()?, required Widget child, Style dropdownStyle = const Style(modifiers: Modifier.reverse), bool focused = false})T> > -
Creates a new popup menu button.
const
Properties
- child → Widget
-
The child widget that acts as the trigger for the popup menu.
final
- dropdownStyle → Style
-
The style applied to the popup menu items.
final
- focused → bool
-
Whether the button is currently focused.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
items
→ List<
PopupMenuItem< T> > -
The list of items to display in the popup menu.
final
- key → Key?
-
The optional key for this widget.
finalinherited
- onCanceled → void Function()?
-
Callback triggered when the menu is dismissed without a selection.
final
- onSelected → void Function(T value)?
-
Callback triggered when an item is selected.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
createElement(
) → Element -
Creates an Element to manage this widget's location in the tree.
inherited
-
createState(
) → State< PopupMenuButton< 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
widthconstraint.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
bufferwithin the specifiedarea.inherited -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited