我想DropdownButton
在页面加载时更改我选择的索引,我该怎么做?
我DropdownButton
是一个PlateType
对象列表,我需要将选定的索引更改为某个表示旧用户选择的索引。以下是我的代码:
DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: false,
child: new DropdownButton<PlateType>(
hint: new Text(
"حرف",
textAlign: TextAlign.center,
style: TextStyle(color: Colors.white),
),
value: selectedPlate,
isExpanded: false,
iconSize: 30,
style: new TextStyle(
color: Colors.white,fontFamily: 'iransans',
),
onChanged: (PlateType pt) {
setState(() {
selectedPlate = pt;
});
},
items: plates.map((PlateType p) {
return new DropdownMenuItem<PlateType>(
value: p,
child: new Text(
p.name,
textAlign: TextAlign.center,
style: new TextStyle(color: Colors.black),
),
);
}).toList(),
)
)
)