I want to change my DropdownButton
selected index on page load, how can I do that?
My DropdownButton
is a list of PlateType
objects and I need to change the selected index to some index that means old user selection.
Following is my code:
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(),
)
)
)