如何在Flutter中获取下拉菜单的selectedIndex?
在DropdownButton中,没有属性可以获取选定的索引,如果需要获取选定的索引,您可以这样做:
new DropdownButton( hint:new Text("Select a users"),value: selectedUser,
onChanged: (String newValue) {
setState(() {
selectedUser = newValue;
});
},
items: userInfoToMap.map((ListOfUsers value) {
return new DropdownMenuItem<String>(
value: value.name,
child:new Text(value.name,style: new TextStyle(color: Colors.black))
);
})
.toList(),
),
),),
userInfoToMap.indexOf(newValue)
是什么意思? - Günter Zöchbauer==
实现)。 - Günter Zöchbauer