Flutter 颤振手柄输入TextFormField键,忽略焦点更改
我在颤振中有一个带有TextFormField的对话框。我想在web上处理用户,点击enter键以接受字段中的值。onFieldSubmitted()方法适用于此,但实际上效果太好了。如果他们甚至把焦点从场上移开,它就会触发。我只想触发回车键。我必须为此使用RawKeyboardListener()吗?或者有没有办法知道触发onfildsubmitted()的不是Enter键而是焦点更改?下面是我的对话框示例代码段。CustomTextField只是我在扩展TextFormField,使其每次都以某种方式显示Flutter 颤振手柄输入TextFormField键,忽略焦点更改,flutter,web,keyboard-events,Flutter,Web,Keyboard Events,我在颤振中有一个带有TextFormField的对话框。我想在web上处理用户,点击enter键以接受字段中的值。onFieldSubmitted()方法适用于此,但实际上效果太好了。如果他们甚至把焦点从场上移开,它就会触发。我只想触发回车键。我必须为此使用RawKeyboardListener()吗?或者有没有办法知道触发onfildsubmitted()的不是Enter键而是焦点更改?下面是我的对话框示例代码段。CustomTextField只是我在扩展TextFormField,使其每次都
var res = await showDialog<String>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Row(
children: <Widget>[
Text('Add '),
Container(
width: 8,
),
DropdownButton(
value: _currentAddType,
items: _addTypeDropDownMenuItems,
onChanged: (value) => _changeAddType(value),
),
],
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0))),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
CustomTextField(
controller: _roomNameController,
textCapitalization: TextCapitalization.words,
autoFocus: true,
icon: Icon(Icons.text_fields),
hint: "Room Name",
onFieldSubmitted: (value) => { // <======== this is the problem, it works even if just losing focus
setState(() {
Navigator.of(context).pop('Add');
})
},
),
Container(
height: 12,
),
Text(
'Select Gateway:',
style: Theme.of(context).textTheme.headline6,
),
Container(
height: 4,
),
DropdownButton(
value: _currentGateway,
items: _gatewayDropDownMenuItems,
onChanged: (String gateway) {
_currentGateway = gateway;
setState(() {
Navigator.of(context)
.pop();
});
_addGatewayOrRoom();
},
),
],
),
),
actions: <Widget>[
FlatButton(
child: Text('Cancel'),
onPressed: () {
setState(() {
Navigator.of(context).pop('Cancel');
});
},
),
Container(
width: 20,
),
FlatButton(
child: Text('Add'),
onPressed: () {
setState(() {
Navigator.of(context).pop('Add');
});
},
),
],
);
},
);
if (res == 'Add') {
await doAddRoom();
_doRefresh();
}
var res=wait showDialog(
上下文:上下文,
禁止:错误,
生成器:(BuildContext上下文){
返回警报对话框(
标题:世界其他地区(
儿童:[
文本(“添加”),
容器(
宽度:8,
),
下拉按钮(
值:_currentAddType,
项目:\添加类型下拉菜单项,
一旦更改:(值)=>\u changeAddType(值),
),
],
),
形状:圆形矩形边框(
borderRadius:borderRadius.all(半径.圆形(8.0)),
内容:SingleChildScrollView(
子:列表体(
儿童:[
自定义文本字段(
控制器:_roomNameController,
textcapitalize:textcapitalize.words,
自动对焦:对,
图标:图标(图标、文本字段),
提示:“房间名称”,
onFieldSubmitted:(值)=>{//