如何监视虚拟键盘的键事件,包括键代码。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) {}
}
Run Code Online (Sandbox Code Playgroud)
我有一个类似的问题,我用这种方式解决了。尝试通过获取文本中的光标位置索引TextEditingController,并使用该索引获取最后键入的值。想象一下下面的示例是 inTextField的onChanged函数,它为您提供插入的文本。
像这样的东西
String key = value.substring(_textController.selection.end-1, _textController.selection.end);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
408 次 |
| 最近记录: |