DropDownButton 和 DropDownMenuItem 的不同样式

Sae*_*ani 9 dart flutter

我正在 Flutter 中创建以下注册表单。

在此处输入图片说明

TextStyle white =
    new TextStyle(color: Colors.white, decorationColor: Colors.white);
TextStyle grey =
    new TextStyle(color: Colors.grey, decorationColor: Colors.white);
Run Code Online (Sandbox Code Playgroud)

我想将白色样式应用于 DropDownButton,将灰色应用于 DropDownMenuItem。但是,DropDownMenu 项的样式也适用于 DDButton。

另外,我可以像 TextField 一样“match_parent” DropDownButton 的宽度(如图像中所示)吗?

这是代码:

     child: new Center(
      child: new ListView(
        shrinkWrap: true,
        padding: new EdgeInsets.only(left: 24.0, right: 24.0),
        children: <Widget>[
          new ListTile(
            leading: const Icon(
              Icons.language,
              color: Colors.white,
            ),
            title: new DropdownButton(
              items:
                  <String>['India', 'Australia', 'USA'].map((String value) {
                return new DropdownMenuItem<String>(
                  value: value,
                  child: new Text(value, ),
                );
              }).toList(),
              value: selected,
              onChanged: (String value) {
                setState(() {
                  selected = value;
                });
              },
              style: white,
            ),
          ),
          new ListTile(
            leading: const Icon(Icons.smartphone, color: Colors.white),
            title: new TextField(
              decoration: new InputDecoration(
                  hintText: "Phone Number", hintStyle: white),
              keyboardType: TextInputType.phone,
              style: white,
            ),
          ),...
Run Code Online (Sandbox Code Playgroud)

Lui*_*vez 2

final bool inherit班级里有这个属性TextStyle,你可以尝试这样的事情:

TextStyle white =
new TextStyle(inherit: false, color: Colors.white, decorationColor: Colors.white);
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

14499 次

最近记录:

6 年,1 月 前