Flutter 如何在Flatter中为下拉标签和下拉列表文本提供不同的颜色?
我正在尝试使用下拉列表,希望所选文本具有Flutter 如何在Flatter中为下拉标签和下拉列表文本提供不同的颜色?,flutter,flutter-layout,Flutter,Flutter Layout,我正在尝试使用下拉列表,希望所选文本具有颜色。白色,下拉列表文本具有颜色。黑色54。但是当我尝试使用color属性并将其更改为白色时,它也会更改下拉文本的颜色 DropdownButton<String>( //this changed the color of both text, intial text as well dropdown text color dropdownColor: Colors
颜色。白色,下拉列表文本具有颜色。黑色54
。但是当我尝试使用color
属性并将其更改为白色时,它也会更改下拉文本的颜色
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 = _;
});
},
)
下拉按钮(
//这改变了文本、初始文本以及下拉文本的颜色
dropdownColor:Colors.white,
价值:价值,
样式:TextStyle(颜色:Colors.white),
图标:CircleAvatar(
半径:12,
背景颜色:Colors.white,
子:图标(图标。箭头下拉),
),
项目:places.map((字符串值){
返回新的DropdownMenuItem(
价值:价值,
儿童:新文本(
价值
//我尝试在这里给出文本样式,但结果相同
样式:TextStyle(颜色:Colors.white),
),
);
}).toList(),
一经更改:(uu){
设置状态(){
值=u0;
});
},
)
这是它的图片
好的,我使用下拉列表的selectedItemBuilder
属性找到了解决方案
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 = _;
});
},
)
final List places=[“德里”、“孟买”、“凯雷拉”、“阿格拉”];
下拉按钮(
选择编辑生成器:(){
归宿
.map((e)=>容器(
对齐:对齐.center,
子:文本(
E
样式:TextStyle(颜色:Colors.white),
),
))
.toList();
},
价值:价值,
图标:CircleAvatar(
半径:12,
背景颜色:Colors.white,
子:图标(图标。箭头下拉),
),
项目:places.map((字符串值){
返回新的DropdownMenuItem(
价值:价值,
儿童:新文本(
价值
样式:TextStyle(颜色:Colors.black54),
),
);
}).toList(),
一经更改:(uu){
设置状态(){
值=u0;
});
},
)
结果如下