designShortcutKeys function

List<String> designShortcutKeys(
  1. BuildContext context,
  2. MenuSerializableShortcut shortcut, {
  3. TargetPlatform? platform,
  4. bool appleSymbols = true,
})

The keys of shortcut (a SingleActivator or a CharacterActivator), one string a key, modifiers first, as Flutter's MenuItemButton labels them:

  • On macOS and iOS, with appleSymbols (the default): ⌃ ⌥ ⇧ ⌘, in Apple's order (⌘ last). Without: the same order in words, Material's where it has one (Ctrl, Shift, Command) and ui_core's where it has none (Option), for a look whose font draws none of ⌃ ⌥ ⇧ ⌘ and ↵.
  • Elsewhere: Alt, Ctrl, the Windows key (Win, on Windows) or Meta, and Shift, in Flutter's order, in the reader's words.

Then the key: an arrow as ← → ↑ ↓; Enter as ↵ (as a word, with Apple's symbols off); a letter or a digit in capitals; Tab, Esc, Space, Delete, Backspace, Home, End, Page Up and Down, and Insert in the reader's words (DesignLocalizations); any other key by its key label. A CharacterActivator's character as it is, with no Shift (the character says it).

platform is defaultTargetPlatform when null. The words come from DesignLocalizations.of at context.

designShortcutKeys(context, const SingleActivator(LogicalKeyboardKey.keyN, meta: true, shift: true))

Implementation

List<String> designShortcutKeys(
  BuildContext context,
  MenuSerializableShortcut shortcut, {
  TargetPlatform? platform,
  bool appleSymbols = true,
}) {
  final words = DesignLocalizations.of(context);
  final on = platform ?? defaultTargetPlatform;
  final apple = on == TargetPlatform.macOS || on == TargetPlatform.iOS;
  final symbols = apple && appleSymbols;
  final keys = shortcut.serializeForMenu();
  final character = keys.character;
  final shift = character == null && (keys.shift ?? false);
  final control = keys.control ?? false;
  final alt = keys.alt ?? false;
  final meta = keys.meta ?? false;
  return [
    if (apple) ...[
      if (control) symbols ? '⌃' : words.keyboardKeyControl,
      if (alt) symbols ? '⌥' : words.keyboardKeyOption,
      if (shift) symbols ? '⇧' : words.keyboardKeyShift,
      if (meta) symbols ? '⌘' : words.keyboardKeyMetaMacOs,
    ] else ...[
      if (alt) words.keyboardKeyAlt,
      if (control) words.keyboardKeyControl,
      if (meta)
        on == TargetPlatform.windows
            ? words.keyboardKeyMetaWindows
            : words.keyboardKeyMeta,
      if (shift) words.keyboardKeyShift,
    ],
    if (character != null)
      character
    else if (keys.trigger case final trigger?)
      _keyLabel(trigger, words, enterSymbol: !apple || symbols),
  ];
}