从下面的代码中,我可以向hint(placeholder)添加填充,但无法为选定的下拉菜单项添加填充
DropdownButtonHideUnderline(
child: DropdownButton(
isExpanded: true,
hint: Padding(
padding: const EdgeInsets.only(left: 10),
child: 'Sort By,
),
items: getDropDownMenuItems(["Name", "Class"]),
value: myActivity,
style: TextStyle(color: Colors.green),elevation: 10,
onChanged: (String value) => {
setState(() {
myActivity = value;
}),
sortList(value)
}),
);
getDropDownMenuItems(options) {
var items = List<DropdownMenuItem<String>>();
for (String option in options) {
items.add(DropdownMenuItem(value: option, child: Text(option)));
}
return items;
}
答案 0 :(得分:2)
尝试为下拉菜单的子项使用填充
getDropDownMenuItems(options) {
var items = List<DropdownMenuItem<String>>();
for (String option in options) {
items.add(DropdownMenuItem(value: option, child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(option),
);));
}
return items;
}