gpt4 book ai didi

Flutter web,禁用对 Tab 按下按钮的关注

转载 作者:行者123 更新时间:2023-12-04 17:20:58 28 4
gpt4 key购买 nike

我有一个文本字段,然后是一个按钮,然后是一个文本字段。
在 Tab 键按下焦点转到第一个 Textfield,在 Tab 键再次按下焦点转到按钮。当按下 Tab 键 2 次时,如何忽略按钮的焦点并将焦点放在第二个文本字段上?

最佳答案

这是结合了onEditingComplete的解决方案和 RawKeyboardListener .onEditingComplete用于捕捉ENTER关键同时 RawKeyboardListener用于 TAB key
enter image description here

class HomePage extends HookWidget {
@override
Widget build(BuildContext context) {
final firstFieldFocusNode = useFocusNode();
final secondFieldFocusNode = useFocusNode();
return Scaffold(
body: Container(
padding: EdgeInsets.all(16.0),
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RawKeyboardListener(
focusNode: firstFieldFocusNode,
onKey: (event) {
if (event.logicalKey == LogicalKeyboardKey.tab) {
secondFieldFocusNode.requestFocus();
}
},
child: TextFormField(
decoration: InputDecoration(labelText: 'First field'),
onEditingComplete: () {
print('ICI');
secondFieldFocusNode.requestFocus();
},
),
),
const SizedBox(height: 48.0),
ElevatedButton(onPressed: () {}, child: Text('CLICK ME')),
const SizedBox(height: 24.0),
TextFormField(
focusNode: secondFieldFocusNode,
decoration: InputDecoration(labelText: 'Second field'),
),
],
),
),
);
}
}

关于Flutter web,禁用对 Tab 按下按钮的关注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66249691/

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