Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何在Flatter中为下拉标签和下拉列表文本提供不同的颜色?_Flutter_Flutter Layout - Fatal编程技术网

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;
});
},
)
结果如下