flutter - 如何在颤振中添加自动填充下拉菜单?
问题描述
我已经做了一个城市的下拉列表,城市列表来自 API。当用户点击 GPS 按钮时,它会自动填充下拉字段。我应该如何在下拉列表中自动填写城市名称?我尝试在文本字段中使用下拉菜单
TextFormField(
controller: city,
decoration:InputDecoration(
border:InputBorder.none,
prefix: DropdownButtonFormField<String>(
decoration: InputDecoration.collapsed(
hintText: 'select',
hintStyle: TextStyle(fontSize: 12,color: Colors.grey.shade600),
),
value:type,
validator: (value) => value == null? 'please select': null,
onChanged: (String newValue) {
setState(() {
type = newValue;
});
},
items: List?.map((item){
return DropdownMenuItem(
onTap: (){
selectedCity=item['city'];
// print(selectedCity);
},
value: item['id'].toString(),
child: Padding(
padding: const EdgeInsets.only(left:15.0,top: 13.0),
child: Text(item['city'],style: TextStyle(fontSize: 12,color: Colors.grey.shade600),),
),
);
})?.toList()??[]
),
),
),
解决方案
您可以使用现成的自动完成包。
一些例子:
https://pub.dev/packages/autocomplete_textfield
推荐阅读
- javascript - 旋转的图像无法在 Google Chrome 浏览器中正确显示
- css - how to force change the primary button text color bootstrap 4 by scss
- c++ - 删除宏扩展的尾随逗号
- php - How to Replace Global Variable for MySQL Connection
- abap - CL_GUI_HTML_VIEWER 获取html源页面
- interface - Python3.8 类型协议:适配器注册表有什么标准吗?
- r - 如果 R 中 data.frame 的一列中存在两个指定值,如何保留一组的所有行
- c# - 对在后台运行异步方法感到困惑
- java - 在 corretto docker 映像中运行 openvpn 失败并出现安全问题
- python - 从长格式 DataFrame2 中的匹配索引中减去 DataFrame1 中的列