MenuButton constructor Null safety
- {required Widget text,
- VoidCallback? onTap,
- Widget? icon,
- MenuSerializableShortcut? shortcut,
- String? shortcutText,
- TextStyle shortcutStyle = const TextStyle(fontWeight: FontWeight.normal, color: Colors.grey)}
A MenuButton is displayed as a button in the menus and submenus.
The following field is necessary: text
.
Assign a Text widget to the text
field. This text is displayed as the button text. You can also wrap your assigned Text around a Padding widget.
Optional fields
To open a submenu on press, assign a SubMenu widget to the submenu
field. IMPORTANT: The onTap
field has to be null
if submenu
is set.
To display a leading icon, assign an Icon widget to the icon
field.
To trigger the onTap
with a keyboard shortcut, assign a MenuSerializableShortcut
to the shortcut
field. For example: SingleActivator(LogicalKeyboardKey.keyS, control: true)
To display a trailing shortcut text, assign a String to the shortcutText
field. You can style this text in the shortcutTextStyle
field.
You can style the MenuButton widgets in the menuButtonStyle
field of your MenuBarWidget.
Implementation
const MenuButton({
required Widget text,
super.onTap,
super.submenu,
super.icon,
super.shortcut,
super.shortcutText,
TextStyle shortcutStyle =
const TextStyle(fontWeight: FontWeight.normal, color: Colors.grey),
}) : super(
menuEntryType: MenuEntryType.MenuButton,
text: text,
shortcutStyle: shortcutStyle);