我希望在 Windows 平台上按键盘上的 Alt+backArrow 时弹出我当前所在的页面。
就像在网络浏览器或 Steam 上一样。
解决方案如下:
您必须用
KeyboardListener
包裹您的脚手架,然后检查是否按下了 alt 和向左箭头,以便您可以弹出页面。
像这样:
List<String> pressedKeys = [];
KeyboardListener(
autofocus: true,
focusNode: FocusNode(),
onKeyEvent: (event) {
String keyLabel = event.logicalKey.keyLabel;
if (keyLabel == 'Alt Right' || keyLabel == 'Alt Left') {
if (event is KeyDownEvent) {
pressedKeys.add('Alt');
} else if (event is KeyUpEvent) {
pressedKeys.remove('Alt');
}
}
if (pressedKeys.contains('Alt')) {
if (event.logicalKey.keyLabel == 'Arrow Left') {
if (event is KeyDownEvent) {
Navigator.of(context).pop();
}
}
}
},
child: Scaffold(
body: Text('test'),
),
);