import 'dart:ui'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; /// [key] with Cmd on Apple platforms and Ctrl elsewhere. SingleActivator primaryShortcut(LogicalKeyboardKey key, {bool shift = false}) { final apple = defaultTargetPlatform == TargetPlatform.macOS || defaultTargetPlatform == TargetPlatform.iOS; return SingleActivator(key, control: !apple, meta: apple, shift: shift); } /// Phones with a D-pad move focus between screen areas with the arrow keys, /// so the soft keyboard closes while browsing. bool get dpadNavigation => defaultTargetPlatform == TargetPlatform.android || defaultTargetPlatform == TargetPlatform.iOS; /// Opens the popup menu behind [key] with its first item focused, so the /// D-pad can move through it. void openMenuWithFocus(GlobalKey> key) { key.currentState?.showButtonMenu(); // The menu takes focus in a microtask after its first frame, so wait for that. WidgetsBinding.instance.addPostFrameCallback((_) => Future(() => FocusManager.instance.primaryFocus?.nextFocus())); } final quitShortcut = primaryShortcut(LogicalKeyboardKey.keyQ); Future quitApp() => ServicesBinding.instance.exitApplication(AppExitType.required);