CheckedPopupMenuItem<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 48 pixels high, which matches the default height of a PopupMenuItem. The horizontal layout uses a 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, 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-only, override
enabled bool
Whether the user is permitted to select this entry. [...]
final, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
height double
The height of the entry. [...]
final, inherited
key Key
Controls how one widget replaces another widget in the tree. [...]
final, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
value → T
The value that will be returned by showMenu if this entry is selected.
final, inherited

Methods

createState() → _CheckedPopupMenuItemState<T>
Creates the mutable state for this widget at a given location in the tree. [...]
override
createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree. [...]
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children. [...]
@protected, inherited
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 toStringDeep. [...]
inherited
toString({DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns 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 ==(dynamic other) bool
The equality operator. [...]
inherited