'Flutter, how to handle keyboard shortcuts
wanna implement keyboard shortcuts into web app, found this example but it doesn't work as expected.
Would like action to occur every time I hold down alt and then press key A, though action occurs only when I press key alt and key A at the same time
thank
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'),
],
),
),
),
),
),
);
}
}
Solution 1:[1]
You can do that in the following way: SingleActivator(LogicalKeyboardKey.keyA, alt: true)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |