PopupMenuButtonModifier<T> class
Displays a menu when pressed and calls onSelected when the menu is dismissed because an item was selected. The value passed to onSelected is the value of the selected menu item.
One of child
or icon may be provided, but not both. If icon is provided,
then PopupMenuButton behaves like an IconButton.
If both are null, then a standard overflow icon is created (depending on the platform).
{@tool dartpad}
This example shows a menu with four items, selecting between an enum's
values and setting a _selectedMenu
field based on the selection
** See code in examples/api/lib/material/popupmenu/popupmenu.0.dart ** {@end-tool}
See also:
- PopupMenuItem, a popup menu entry for a single value.
- PopupMenuDivider, a popup menu entry that is just a horizontal line.
- CheckedPopupMenuItem, a popup menu item with a checkmark.
- showMenu, a method to dynamically show a popup menu at a given location.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- SingleChildStatelessModifier
- PopupMenuButtonModifier
- Available extensions
Constructors
-
PopupMenuButtonModifier({Key? key, Widget? child, Key? modifierKey, required PopupMenuItemBuilder<
T> itemBuilder, T? initialValue, PopupMenuItemSelected<T> ? onSelected, PopupMenuCanceled? onCanceled, String? tooltip, double? elevation, EdgeInsetsGeometry padding = const EdgeInsets.all(8.0), double? splashRadius, Widget? icon, double? iconSize, Offset offset = Offset.zero, bool enabled = true, ShapeBorder? shape, Color? color, bool? enableFeedback, BoxConstraints? constraints, PopupMenuPosition position = PopupMenuPosition.over}) -
Creates a button that shows a popup menu.
const
Properties
- color → Color?
-
If provided, the background color used for the menu.
final
- constraints → BoxConstraints?
-
Optional size constraints for the menu.
final
- elevation → double?
-
The z-coordinate at which to place the menu when open. This controls the
size of the shadow below the menu.
final
- enabled → bool
-
Whether this popup menu button is interactive.
final
- enableFeedback → bool?
-
Whether detected gestures should provide acoustic and/or haptic feedback.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- icon → Widget?
-
If provided, the icon is used for this button
and the button will behave like an IconButton.
final
- iconSize → double?
-
If provided, the size of the Icon.
final
- initialValue → T?
-
The value of the menu item, if any, that should be highlighted when the menu opens.
final
-
itemBuilder
→ PopupMenuItemBuilder<
T> -
Called when the button is pressed to create the items to show in the menu.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- modifierKey → Key?
-
The actual key of the widget, which Modifier wrapped
finalinherited
- offset → Offset
-
The offset is applied relative to the initial position
set by the position.
final
- onCanceled → PopupMenuCanceled?
-
Called when the user dismisses the popup menu without selecting an item.
final
-
onSelected
→ PopupMenuItemSelected<
T> ? -
Called when the user selects a value from the popup menu created by this button.
final
- padding → EdgeInsetsGeometry
-
Matches IconButton's 8 dps padding by default. In some cases, notably where
this button appears as the trailing element of a list item, it's useful to be able
to set the padding to zero.
final
- position → PopupMenuPosition
-
Whether the popup menu is positioned over or under the popup menu button.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- shape → ShapeBorder?
-
If provided, the shape used for the menu.
final
- splashRadius → double?
-
The splash radius.
final
- tooltip → String?
-
Text that describes the action that will occur when the button is pressed.
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
inherited
-
buildWithChild(
BuildContext context, Widget? child) → Widget -
A build method that receives an extra
child
parameter.override -
createElement(
) → SingleChildStatelessElement -
Create a SingleChildStatelessElement
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}) → 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