【发布时间】:2020-12-31 07:40:35
【问题描述】:
我已经做了一个城市的下拉列表,城市列表来自 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()??[]
),
),
),
【问题讨论】:
标签: flutter dropdown textfield autofill