我正在尝试使用下拉列表,并希望具有Colors.white
选定的文本和Colors.black54
下拉列表的文本。但是,当我尝试使用color
attribute并将其更改为White时,它也会更改下拉文本的颜色。
DropdownButton<String>(
//this changed the color of both text, intial text as well dropdown text color
dropdownColor: Colors.white,
value: value,
style: TextStyle(color: Colors.white),
icon: CircleAvatar(
radius: 12,
backgroundColor: Colors.white,
child: Icon(Icons.arrow_drop_down),
),
items: places.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(
value,
//I tried giving text style here , but same result
style: TextStyle(color: Colors.white),
),
);
}).toList(),
onChanged: (_) {
setState(() {
value = _;
});
},
)
这是它的图片。
好的,我使用的selectedItemBuilder
属性找到了解决方案dropdown
final List<String> places = ['Delhi', 'Mumbai', 'Kerela', 'Agra'];
DropdownButton<String>(
selectedItemBuilder: (_) {
return places
.map((e) => Container(
alignment: Alignment.center,
child: Text(
e,
style: TextStyle(color: Colors.white),
),
))
.toList();
},
value: value,
icon: CircleAvatar(
radius: 12,
backgroundColor: Colors.white,
child: Icon(Icons.arrow_drop_down),
),
items: places.map((String value) {
return new DropdownMenuItem<String>(
value: value,
child: new Text(
value,
style: TextStyle(color: Colors.black54),
),
);
}).toList(),
onChanged: (_) {
setState(() {
value = _;
});
},
)
这是结果
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句