children property

List<Widget> children

The list of menu items that are the top level children of the MenuBar.

A Widget in Flutter is immutable, so directly modifying the children with List APIs such as someMenuBarWidget.menus.add(...) will result in incorrect behaviors. Whenever the menus list is modified, a new list object must be provided.

Menus using MenuItemButton can have a SingleActivator or CharacterActivator assigned to them as their MenuItemButton.shortcut, which will display an appropriate shortcut hint. Even though the shortcut labels are displayed in the menu, shortcuts are not automatically handled. They must be available in whatever context they are appropriate, and handled via another mechanism.

If shortcuts should be generally enabled, but are not easily defined in a context surrounding the menu bar, consider registering them with a ShortcutRegistry (one is already included in the WidgetsApp, and thus also MaterialApp and CupertinoApp), as shown in the example below. To be sure that selecting a menu item and triggering the shortcut do the same thing, it is recommended that they call the same callback.

This example shows a MenuBar that contains a single top level menu, containing three items: "About", a checkbox menu item for showing a message, and "Quit". The items are identified with an enum value, and the shortcuts are registered globally with the ShortcutRegistry.

To create a local project with this code sample, run:
flutter create --sample=material.MenuBar.1 mysample


final List<Widget> children;