CheckedPopupMenuItemModifier<T> class

An item with a checkmark in a Material Design popup menu.

To show a popup menu, use the showMenu function. To create a button that shows a popup menu, consider using PopupMenuButton.

A CheckedPopupMenuItem is kMinInteractiveDimension pixels high, which matches the default minimum height of a PopupMenuItem. The horizontal layout uses ListTile; the checkmark is an Icons.done icon, shown in the ListTile.leading position.

{@tool snippet}

Suppose a Commands enum exists that lists the possible commands from a particular popup menu, including Commands.heroAndScholar and Commands.hurricaneCame, and further suppose that there is a _heroAndScholar member field which is a boolean. The example below shows a menu with one menu item with a checkmark that can toggle the boolean, and one menu item without a checkmark for selecting the second option. (It also shows a divider placed between the two menu items.)

PopupMenuButton<Commands>(
  onSelected: (Commands result) {
    switch (result) {
      case Commands.heroAndScholar:
        setState(() { _heroAndScholar = !_heroAndScholar; });
        break;
      case Commands.hurricaneCame:
        // ...handle hurricane option
        break;
      // ...other items handled here
    }
  },
  itemBuilder: (BuildContext context) => <PopupMenuEntry<Commands>>[
    CheckedPopupMenuItem<Commands>(
      checked: _heroAndScholar,
      value: Commands.heroAndScholar,
      child: const Text('Hero and scholar'),
    ),
    const PopupMenuDivider(),
    const PopupMenuItem<Commands>(
      value: Commands.hurricaneCame,
      child: ListTile(leading: Icon(null), title: Text('Bring hurricane')),
    ),
    // ...other items listed here
  ],
)

{@end-tool}

In particular, observe how the second menu item uses a ListTile with a blank Icon in the ListTile.leading position to get the same alignment as the item with the checkmark.

See also:

  • PopupMenuItem, a popup menu entry for picking a command (as opposed to toggling a value).
  • PopupMenuDivider, a popup menu entry that is just a horizontal line.
  • showMenu, a method to dynamically show a popup menu at a given location.
  • PopupMenuButton, an IconButton that automatically shows a menu when it is tapped.
Inheritance
Available extensions

Constructors

CheckedPopupMenuItemModifier({Key? key, Key? modifierKey, T? value, bool checked = false, bool enabled = true, EdgeInsets? padding, double height = kMinInteractiveDimension, MouseCursor? mouseCursor, Widget? child})
Creates a popup menu item with a checkmark.
const

Properties

checked bool
Whether to display a checkmark next to the menu item.
final
enabled bool
Whether the user is permitted to select this item.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
height double
The minimum height of the menu item.
finalinherited
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
mouseCursor MouseCursor?
The cursor for a mouse pointer when it enters or is hovering over the widget.
finalinherited
onTap VoidCallback?
Called when the menu item is tapped.
finalinherited
padding EdgeInsets?
The padding of the menu item.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
textStyle TextStyle?
The text style of the popup menu item.
finalinherited
value → T?
The value that will be returned by showMenu if this entry is selected.
finalinherited

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