flutter - Flutter,如何处理键盘快捷键
问题描述
想在网络应用程序中实现键盘快捷键,找到了这个例子,但它没有按预期工作。
希望每次按住 alt 然后按键 A 时都会发生动作,尽管只有当我同时按下键 alt 和键 A 时才会发生动作
感谢
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(MyApp());
class MyIntent extends Intent {}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
int integer = 0;
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Shortcuts(
shortcuts: {
LogicalKeySet(LogicalKeyboardKey.alt, LogicalKeyboardKey.keyA):
MyIntent(),
},
child: Actions(
actions: {
MyIntent: CallbackAction(onInvoke: (i) {
print('rocks!!!' '$integer');
integer++;
return null;
}),
},
child: Focus(
autofocus: true,
child: SizedBox(
height: 200,
width: 500,
child: Column(
children: <Widget>[
const Text('List of Homework'),
],
),
),
),
),
),
);
}
}
解决方案
推荐阅读
- apache - 一个IP 两个虚拟机
- django - docker 卡在 pip install 上
- javascript - 反应钩子:超过最大深度
- chart.js - 如何设置水平条形图的类别高度?
- python - Pandas.pivot_table 和将数据集从一种形式转换为另一种形式的问题
- reactjs - 如何测试 redux 操作?
- javascript - JS - 通过按钮将 div 的可见性设置为隐藏
- php - Nginx 将图像重定向到页面
- highcharts - Highchart 热图工具提示在 HeaderFormat 中获取 x 或键
- javascript - npm 错误!代码 ENOENT 和 npm ERR!系统调用产生 C:\Program Files\nodejs\node.exe