import 'package:flutter/widgets.dart'; import '../features/settings/keyboard_shortcuts_help.dart'; /// Opens and closes the keyboard shortcuts cheatsheet from the shell's global /// key handler. Ctrl+? (or Escape) closes it, and it is only ever popped once: /// closing clears the token first, and a dismissal by the barrier or close /// button clears it when the route completes. class ShellCheatsheet { Object? _token; bool get isOpen => _token != null; void toggle(BuildContext context) { if (isOpen) { close(context); } else { open(context); } } void open(BuildContext context) { if (isOpen) return; final token = _token = Object(); showKeyboardShortcutsHelp(context, focusSearch: true).whenComplete(() { if (identical(_token, token)) _token = null; }); } void close(BuildContext context) { if (!isOpen) return; _token = null; Navigator.of(context, rootNavigator: true).maybePop(); } }