如何在 Flutter 中使下拉标签和下拉列表文本具有不同的颜色?

med*_*tat 4 flutter flutter-layout

我正在尝试使用下拉菜单,并希望用于Colors.white所选文本和Colors.black54下拉列表的文本。但是当我尝试使用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 = _;
                      });
                    },
                  )
Run Code Online (Sandbox Code Playgroud)

这是它的图片。

在此输入图像描述 在此输入图像描述

med*_*tat 8

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 = _;
                      });
                    },
                  )
Run Code Online (Sandbox Code Playgroud)

这是结果

在此输入图像描述 在此输入图像描述