flutter - 如何在颤动中实现带有下拉前缀的文本字段
问题描述
我怎样才能在颤振中实现这一目标?我尝试将 DropdownButton 用作 a 中的子级,prefixIcon
但InputDecoration
效果TextFormField
不佳。我很想知道人们在面对这样的挑战时将如何解决这个问题。
解决方案
您可以使用 aListTile
并将 and 放入a并将DropDownButton
the设置为。用于制作圆角。TextField
Row
Row
title
ListTile
ClipRRect
ListTile(
title: ClipRRect(
borderRadius: BorderRadius.circular(50.0),
child: Container(
color: Colors.black12,
child: Row(
children: [
_buildDropDownButton('USD'),
Expanded(
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
),
controller: textController,
style:
TextStyle(fontSize: 20.0, color: Colors.black),
keyboardType:
TextInputType.numberWithOptions(decimal: true),
),
),
],
),
),
),
)
Widget _buildDropDownButton(String currencyCategory) {
return Container(
color: Colors.deepPurple,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 5),
child: DropdownButtonHideUnderline(
child: DropdownButton(
iconEnabledColor: Colors.white,
style: TextStyle(
color: Colors.white,
),
dropdownColor: Colors.deepPurple,
value: currencyCategory,
items: ['USD', 'EUR']
.map((String value) => DropdownMenuItem(
value: value,
child: Row(
children: <Widget>[
Text(value),
],
),
))
.toList(),
onChanged: (value) {},
),
),
),
);
}
结果:
推荐阅读
- docker - Flask + Gunicorn + NGINX 静态文件?
- react-native - 具有 onSubmit 功能的导航 stackNavigator
- powershell - 我如何使用 Copy-Item cmdlet 有什么问题吗?
- javascript - 如何将字符串数组转换为 JSON 对象?
- actions-on-google - Google Action 不会再次调用我的 oauth 令牌端点
- python - 如何在 Python 中更改 Delaunay 点的颜色?
- python-3.x - 选择两个数据框之间的缺失行
- java - 使用 Spring 使用 multipartfile 测试 POST 请求
- postgresql - Diesel 打印模式不会生成可连接!对于外键(postgresql)
- python - 相同列的 Pandas 断言错误