gpt4 book ai didi

flutter - 如何在 Flutter 中检测虚拟键盘事件

转载 作者:IT老高 更新时间:2023-10-28 12:47:11 28 4
gpt4 key购买 nike

如何监控虚拟键盘的按键事件,包括keycode。 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 获取文本中的光标位置索引,并使用该索引获取最后输入的值。想象一下下面的例子是在 TextFieldonChanged 函数中,它给你插入文本。

类似的东西

String key = value.substring(_textController.selection.end-1, _textController.selection.end);

关于flutter - 如何在 Flutter 中检测虚拟键盘事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51743114/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com