EnhancedPlatformMenu class

EnhancedPlatformMenu & EnhancedPlatformMenuItem

A small extension layer over Flutter’s platform menu API that adds:

  • Top-level menus with identifiers (EnhancedPlatformMenu.standard) to map onto well-known system menus (e.g., File, Edit). On macOS you must provide a custom label (asserted).
  • Custom top-level menus (EnhancedPlatformMenu.custom) with optional EnhancedPlatformMenuIcon.
  • Per-item enhancements via EnhancedPlatformMenuItem:
    • checked: renders a checkmark state where the host supports it.
    • icon: attaches an EnhancedPlatformMenuIcon (SF Symbol or asset).
  • Item grouping via EnhancedPlatformMenuItemGroup to cluster related items; separators between groups are inserted by the delegate during serialization.

Classes

  • EnhancedPlatformMenu extends PlatformMenuItem
    • menus: child PlatformMenuItems (including groups/items/submenus).
    • identifier: a StandardMenuIdentifier for system-mapped menus.
    • removeDefaultItems: hint to strip OS-provided defaults when building a standard menu (actual behavior is platform-dependent).
    • icon: optional menu icon for custom menus.
  • StandardMenuIdentifier: enumerates common system menus (e.g., file, edit, window, help; services is macOS-only).
  • EnhancedPlatformMenuItem extends PlatformMenuItem
    • Adds checked and icon. Channel representation includes all base fields plus checked and (if present) serialized icon data.
  • EnhancedPlatformMenuItemGroup extends PlatformMenuItemGroup
    • Groups multiple items

Example

final fileMenu = EnhancedPlatformMenu.standard(
  identifier: StandardMenuIdentifier.file,
  label: 'File',
  menus: [
    EnhancedPlatformMenuItem(label: 'New', checked: false),
    EnhancedPlatformMenuItemGroup(members: [
      EnhancedPlatformMenuItem(label: 'Open…'),
      EnhancedPlatformMenuItem(label: 'Close'),
    ]),
  ],
  removeDefaultItems: true,
);
Inheritance

Constructors

EnhancedPlatformMenu.custom({required String label, required List<PlatformMenuItem> menus, EnhancedPlatformMenuIcon? icon})
factory
EnhancedPlatformMenu.standard({required StandardMenuIdentifier identifier, String? label, required List<PlatformMenuItem> menus, bool removeDefaultItems = false})
factory

Properties

descendants List<PlatformMenuItem>
Returns all descendant PlatformMenuItems of this item.
no setterinherited
hashCode int
The hash code for this object.
no setteroverride
icon EnhancedPlatformMenuIcon?
final
identifier StandardMenuIdentifier?
final
label String
The required label used for rendering the menu item.
finalinherited
members List<PlatformMenuItem>
Returns the list of group members if this menu item is a "grouping" menu item, such as PlatformMenuItemGroup.
no setterinherited
final
onClose VoidCallback?
Returns a callback, if any, to be invoked if the platform menu receives a "Menu.closed" method call from the platform for this item.
no setterinherited
onOpen VoidCallback?
Returns a callback, if any, to be invoked if the platform menu receives a "Menu.opened" method call from the platform for this item.
no setterinherited
onSelected VoidCallback?
An optional callback that is called when this PlatformMenuItem is selected.
finalinherited
onSelectedIntent Intent?
An optional intent that is invoked when this PlatformMenuItem is selected.
finalinherited
removeDefaultItems bool
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shortcut MenuSerializableShortcut?
The optional shortcut that selects this PlatformMenuItem.
finalinherited

Methods

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
toChannelRepresentation(PlatformMenuDelegate delegate, {required MenuItemSerializableIdGenerator getId}) Iterable<Map<String, Object?>>
Converts the representation of this item into a map suitable for sending over the default "flutter/menu" channel used by DefaultPlatformMenuDelegate.
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
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode.
inherited

Operators

operator ==(Object other) bool
The equality operator.
override