如何让alt+左箭头在颤动中返回?

问题描述 投票:0回答:1

我希望在 Windows 平台上按键盘上的 Alt+backArrow 时弹出我当前所在的页面。

就像在网络浏览器或 Steam 上一样。

flutter windows dart keyboard-shortcuts
1个回答
0
投票

解决方案如下:

您必须用

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'),
  ),
);
© www.soinside.com 2019 - 2024. All rights reserved.