import 'package:flutter/foundation.dart'; /// Where an app-wide chat shortcut goes: Ctrl+K / Alt+K pressed on the Chat /// destination (the quick switcher), Alt+N (New chat) and Alt+J (the next /// chat needing the operator). The mounted chat screen attaches its action /// here, and the app runs it. class ChatQuickSwitchRequests { VoidCallback? _toggle; /// Makes [toggle] the switcher; the last attached one wins. void attach(VoidCallback toggle) => _toggle = toggle; /// Detaches [toggle] if it is still the attached one. void detach(VoidCallback toggle) { if (_toggle == toggle) _toggle = null; } /// Opens the switcher, or closes it when open. False when no chat screen /// is mounted to show it. bool toggle() { final toggle = _toggle; if (toggle == null) return false; toggle(); return true; } }