Skip to content

Add .toolTip property to PlatformMenuBar's PlatformMenuItem class #180031

@driftwoodstudio

Description

@driftwoodstudio

Use case

When writing MacOS applications, one is forced to use PlatformMenuBar and related classes to interact with the native MacOS menu system.

PlatformMenuBar's PlatformMenuItem class has no way to specify a tooltip for menu items . This is extremely common on MacOS (e.g. the "Open Recent" menu items in BBEdit, etc).

Both native MacOS and the for-Windows-platform MenuBar widget allow addition of tooltips to menu items.

Thus Mac platform flutter applications lack a capability that both flutter-on-windows and native-macos applications have.

Windows

The Windows alternative to PlatformMenuBar, the flutter SDK MenuBar widget, allows easy addition of tooltips for menus using a Tooltip widget:

MenuItemButton(
  child: Tooltip(
    message: 'Open an existing file',
    child: Text('Open'),
  ),

Native MacOS

In native MacOS, tooltips can be added easily by using the .toolTip property of NSMenuItem as documented at: https://developer.apple.com/documentation/appkit/nsmenuitem

Flutter-on-MacOS

No capability exists to specify a tooltip for a menu item. See: https://api.flutter.dev/flutter/widgets/PlatformMenuItem-class.html

Only a String .label can be set.

Proposal

Feature parity with flutter-on-windows and native-macos could be accomplished by:

  • adding a .toolTip parameter to flutter's PlatformMenuItem widget
  • including that parameter in the serialization of data to pass through the native bridge
  • including that parameter in de-serialization of data in macOS native code
  • applying the parameter when creating NSMenuItem instances

PlatformMenuBar uses the MacOS NSMenuItem class directly for actual native implementation. (See: https://github.com/flutter/flutter/blob/master/engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterMenuPlugin.mm)

NSMenuItem already accepts an optional string for .toolTip (which flutter does not use).

All the pieces are there, it just needs an expansion of the parameter set from Dart code through to the NSMenuItem object instantiation.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: desktopRunning on desktopc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.platform-macBuilding on or for macOS specificallyr: solvedIssue is closed as solvedteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions