![](/img/trans.png)
[英]How to Change the splash color when tapping DropdownButton In flutter?
[英]Prevent keyboard dismiss when tapping DropdownButton
这个问题与颤振有关。 我在 TextField 上方有一个 DropdownButton,如下所示:
DropdownButton<String>(
isExpanded: true,
hint: Text(associatedHint),
disabledHint: Text(associatedHint),
items: diagnosesList.map((int value) {
return DropdownMenuItem<String>(
value: value.toString(),
child: Text(dxDisplay),
);
}).toList(),
value: ANID,
onChanged: (String newANID) {
setState(() {
ANID = newANID;
});
},
),
TextField(
autofocus: true,
keyboardType: keyboardType,
maxLines: maxLines,
textCapitalization: TextCapitalization.sentences,
controller: _textEntryController,
decoration: InputDecoration(hintText: "Entry"),
onChanged: (value) {
noteEntry = value;
},
),
TextField 自动对焦立即调出键盘。 当您点击 DropdownButton 时,它会从 TextField 中移除焦点,从而关闭键盘。 这会在屏幕上移动内容并创建糟糕的用户体验。
有关如何解决此问题的任何建议? 即使在点击 DropdownButton 后,有没有办法让键盘保持打开状态?
终于找到了解决办法。 需要将 AlertDialog 包装在 SingleChildScrollView 中。 这会在屏幕顶部打开 AlertDialog,并且在键盘打开/关闭时不会移动它。 它还确保如果内容太长(垂直),它可以在键盘下滑动,用户可以使用滚动手势查看隐藏内容/与隐藏内容交互。
return SingleChildScrollView(
child: AlertDialog(
title: alertTitle,
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget> [
DropdownButton<String>(
.......
),
TextField(
autofocus: true,
.......
),
],
),
)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.