import 'package:flutter/material.dart'; import '../../ui/adaptive/app_popups.dart'; import 'keyboard_shortcuts_registry.dart'; const keyboardShortcutsLabel = 'Keyboard shortcuts'; Future showKeyboardShortcutsHelp(BuildContext context) => showAppDetails( context, maxWidth: 640, builder: (_) => const KeyboardShortcutsHelp(), ); class KeyboardShortcutsHelp extends StatelessWidget { const KeyboardShortcutsHelp({super.key, this.registry}); final KeyboardShortcutRegistry? registry; @override Widget build(BuildContext context) { final entries = (registry ?? KeyboardShortcutRegistry.current()).entries; final content = Semantics( scopesRoute: true, namesRoute: true, explicitChildNodes: true, label: 'Keyboard shortcuts help', child: Padding( padding: const EdgeInsets.fromLTRB(24, 8, 24, 24), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Row( children: [ Expanded( child: Text( keyboardShortcutsLabel, style: Theme.of(context).textTheme.headlineSmall, ), ), IconButton( tooltip: 'Close keyboard shortcuts', onPressed: () => Navigator.of(context).pop(), icon: const Icon(Icons.close), ), ], ), const SizedBox(height: 8), Text( 'Shortcuts available in the current app and browser environment.', style: Theme.of(context).textTheme.bodyMedium, ), const SizedBox(height: 16), for (final (index, entry) in entries.indexed) ...[ if (index > 0) const Divider(height: 1), Padding( padding: const EdgeInsets.symmetric(vertical: 12), child: _ShortcutRow(entry: entry), ), ], const SizedBox(height: 4), Text( 'On macOS, Option is shown for Alt. Browsers can reserve system or tab shortcuts.', style: Theme.of(context).textTheme.bodySmall, ), ], ), ), ); // The desktop details dialog supplies its own bounded scroll view. The // narrow details sheet does not, so keep the help readable at large text // scales and on short phone screens there as well. return usesDesktopPopups(context) ? content : SingleChildScrollView(child: content); } } class _ShortcutRow extends StatelessWidget { const _ShortcutRow({required this.entry}); final KeyboardShortcutEntry entry; @override Widget build(BuildContext context) => Semantics( container: true, label: '${entry.action}: ${entry.keys}${entry.caveat == null ? '' : '. ${entry.caveat}'}', child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded(child: Text(entry.action)), const SizedBox(width: 16), Flexible( child: Text( entry.keys, textAlign: TextAlign.end, style: const TextStyle(fontWeight: FontWeight.w600), ), ), ], ), if (entry.caveat case final caveat?) ...[ const SizedBox(height: 4), Text(caveat, style: Theme.of(context).textTheme.bodySmall), ], ], ), ); }