[英]How Detect virtual keyboard events in Flutter
如何监控虚拟键盘的关键事件,包括键码。 RawKeyboardListener对虚拟键盘键没有影响。
void _onkeyclick(RawKeyEvent event) {
if (event is RawKeyDownEvent) {
if (event.data is RawKeyEventDataAndroid) {
RawKeyDownEvent rawKeyDownEvent = event;
RawKeyEventDataAndroid rawKeyEventDataAndroid = rawKeyDownEvent.data;
print(rawKeyEventDataAndroid.keyCode);
switch (rawKeyEventDataAndroid.keyCode) {
case 66:
}
}
}
}
Widget getItem(Pbtem pb) {
if (pb.type == 1) {
TextEditingController _c = new TextEditingController();
return new RawKeyboardListener(
focusNode: _focusNode,
onKey: _onkeyclick,
child: new EditableText(
controller: _c,
focusNode: _focusNode,
style: TextStyle(
color: Colors.black,
fontSize: 18.0,
),
keyboardType: TextInputType.multiline,
cursorColor: Colors.blue,
));
} else if (pb.type == 2) {}
}
我有类似的问题,我以这种方式解决了它。 尝试通过TextEditingController
在文本中获取光标位置索引,并使用该索引获取最后输入的值。 想象一下下面的例子是在TextField
的onChanged
函数中,它为你提供插入的文本。
像这样的东西
String key = value.substring(_textController.selection.end-1, _textController.selection.end);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.