wip: shortcut listener widget.

This commit is contained in:
2021-11-10 18:40:51 +08:00
parent 4eb7bc256c
commit 930fd5ddf7
7 changed files with 131 additions and 106 deletions
+3 -2
View File
@@ -126,8 +126,9 @@ class _DButtonState extends State<DButton> {
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
borderColor:
_hovering ? widget.activeBorderColor ?? context.watch<SettingsProvider>().activeColor : Color(0xff565656),
borderColor: _hovering
? (widget.activeBorderColor ?? context.watch<SettingsProvider>().currentActiveColor)
: Color(0xff565656),
borderWidth: 2,
borderRadius: BorderRadius.circular(defaultBorderRadius),
child: MouseRegion(
@@ -1,7 +1,9 @@
import 'package:dde_gesture_manager/constants/constants.dart';
import 'package:dde_gesture_manager/constants/keyboard_mapper.dart';
import 'package:dde_gesture_manager/models/settings.provider.dart';
import 'package:flutter/material.dart';
import 'package:dde_gesture_manager/extensions.dart';
import 'package:flutter/services.dart';
class TableCellShortcutListener extends StatefulWidget {
final double width;
@@ -16,28 +18,62 @@ class TableCellShortcutListener extends StatefulWidget {
}) : super(key: key);
@override
_TableCellShortcutListenerState createState() =>
_TableCellShortcutListenerState();
_TableCellShortcutListenerState createState() => _TableCellShortcutListenerState();
}
class _TableCellShortcutListenerState extends State<TableCellShortcutListener> {
List<String> _shortcut = [];
bool inputMode = false;
FocusNode _focusNode = FocusNode();
_handleFocusChange() {
if (!_focusNode.hasFocus) {
widget.onComplete(_shortcut.join('+'));
}
}
_tryToAddKey(LogicalKeyboardKey key) {
if (key.keyLabel.length == 1) key.keyLabel.sout();
late String _key;
if (keyMapper.containsKey(key))
_key = keyMapper[key]!;
else if (key.keyLabel.length == 1) _key = key.keyLabel.toLowerCase();
if (!_shortcut.contains(_key)) {
setState(() {
_shortcut.add(_key);
});
}
}
@override
void initState() {
_shortcut = widget.initShortcut.split('+');
_focusNode.addListener(_handleFocusChange);
super.initState();
}
@override
void dispose() {
_focusNode.removeListener(_handleFocusChange);
super.dispose();
}
@override
Widget build(BuildContext context) {
return RawKeyboardListener(
focusNode: FocusNode(),
focusNode: _focusNode,
onKey: (evt) {
evt.sout();
RawKeyboard.instance.keysPressed.forEach(_tryToAddKey);
RawKeyboard.instance.keysPressed.sout();
},
child: GestureDetector(
onTap: () {},
onTap: () {
setState(() {
_shortcut = [];
inputMode = true;
});
},
child: Focus(
autofocus: true,
onKeyEvent: (_, __) => KeyEventResult.skipRemainingHandlers,
@@ -50,8 +86,7 @@ class _TableCellShortcutListenerState extends State<TableCellShortcutListener> {
border: Border.all(
width: 2,
color: Focus.of(context).hasFocus
? context.watch<SettingsProvider>().activeColor ??
Color(0xff565656)
? context.watch<SettingsProvider>().activeColor ?? Color(0xff565656)
: Color(0xff565656)),
),
child: Align(
@@ -66,27 +101,16 @@ class _TableCellShortcutListenerState extends State<TableCellShortcutListener> {
padding: const EdgeInsets.symmetric(horizontal: 2.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(
defaultBorderRadius / 2),
borderRadius: BorderRadius.circular(defaultBorderRadius / 2),
color: context.t.dialogBackgroundColor,
border: Border.all(
width: 1,
color: Focus.of(context).hasFocus
? context
.watch<SettingsProvider>()
.activeColor ??
Color(0xff565656)
: Color(0xff565656)),
border: Border.all(width: 1, color: Color(0xff565656)),
),
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 5.0),
padding: const EdgeInsets.symmetric(horizontal: 5.0),
child: Text(
e,
e.notNull ? e : LocaleKeys.str_null.tr(),
style: TextStyle(
color: context
.watch<SettingsProvider>()
.activeColor,
color: context.watch<SettingsProvider>().activeColor,
),
),
),