我有一个文本框和一个下拉按钮在屏幕上。当我从文本框中选择一个项目,然后返回到textfield时,我发现这有点尴尬。
我的问题是,您必须点击两次,一次退出文本字段,第二次访问下拉列表-有方法退出文本框,并在一个点击打开下拉列表吗?这是内置在Android还是颤振控制中的?
下面是一些显示下拉和文本框的颤振代码.
class _TextAndDropdownState extends State<TextAndDropdown> {
int selectedDropdown;
String selectedText;
final textController = new TextEditingController();
@override
void initState() {
super.initState();
selectedDropdown = 1;
textController.addListener(() => print(''));
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Text and dropdown'),
),
body: Container(
child: Column(
children: [
Padding(
padding: EdgeInsets.all(10.0),
),
DropdownButton(value: selectedDropdown, onChanged: _dropdownChange, items: [
DropdownMenuItem(
child: Text('First'),
value: 1,
),
DropdownMenuItem(child: Text('Seconds')),
]),
TextField(controller: textController),
],
),
),
);
}
void _dropdownChange(val) {
setState(() {
selectedDropdown = val;
});
}
}发布于 2019-01-18 12:28:02
抱歉你的回答太迟了..。我也在为这个找到解决办法。现在我明白了。
只是你得加上这个
FocusScope.of(context).requestFocus(new FocusNode());在您的
_dropdownChange(val)法
void _dropdownChange(val) {
FocusScope.of(context).requestFocus(new FocusNode());///It will clear all focus of the textfield
setState(() {
selectedDropdown = val;
});
}https://stackoverflow.com/questions/51534205
复制相似问题