CheckedPopupMenuItem<T> class Null safety

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.

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
  ],
)

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

Constructors

CheckedPopupMenuItem({Key? key, 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
child → Widget?
The widget below this widget in the tree.
read-onlyoverride
enabled → bool
Whether the user is permitted to select this item.
finalinherited
hashCode → int
The hash code for this object.
nonVirtual">@nonVirtualread-onlyinherited
height → double
The minimum height of the menu item.
finalinherited
key → Key?
Controls how one widget replaces another widget in the tree.
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.
read-onlyinherited
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

createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → PopupMenuItemState<T, CheckedPopupMenuItem<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.
protected">@protectedinherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
represents(T? value) → bool
Whether this entry represents a particular value.
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.
nonVirtual">@nonVirtualinherited