Flutter 键盘快捷键
您想添加的键盘快捷键。
示例
当按下 Control + P 时,用户将导航到 SecondPage(),helpLabel 将显示在帮助菜单中。
KeyBoardShortcuts(
keysToPress: {LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.keyP},
onKeysPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondPage()),
),
helpLabel: "Go to Second Page",
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
),
如果 globalShortcuts 设置为 true,用户可以使用 Home 按钮转到主页,使用向上和向下按钮转到页面顶部或底部,使用 Escape 键转到上一页。
KeyBoardShortcuts(
globalShortcuts: true,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
),
initShortCuts() 用于自定义快捷键,您可以设置主页、帮助菜单标题、自定义快捷键图标和自定义帮助菜单。
initShortCuts(HomePage(), helpTitle : "Help Menu", helpIcon : Icons.menu);
您还可以使用 initShortCuts 来创建自己的全局快捷键,当 globalShortcuts 设置为 true 时,这些快捷键将在所有页面中使用,而无需重写这些快捷键。
initShortCuts(
HomePage(),
keysToPress: {
{LogicalKeyboardKey.controlLeft, LogicalKeyboardKey.keyP},
},
onKeysPressed: {() => print("Work")},
helpLabel: {"Print Work"},
);
