选择选项时 Flutter DropdownButton 显示标签

Cip*_*ian 14 flutter

可以Dropdown Button

 return DropdownButton<String>(
          items: <String>['Foo', 'Bar'].map((String value) {
            return new DropdownMenuItem<String>(
              value: value,
              child: new Text(value),
            );
          }).toList(),
          onChanged: (_) {},
        );
Run Code Online (Sandbox Code Playgroud)

在 a 中有类似于装饰用户的东西TextFormField

      TextFormField(
        controller: _titleController,
        decoration: InputDecoration(labelText: 'Input'),
        validator: (String value) {
          if (value != null && value.isEmpty) {
            return 'Please enter some text';
          }
        },
        style: Theme.of(context).textTheme.title,
      ),
Run Code Online (Sandbox Code Playgroud)

当在上面的 TextFormField 中写一些东西时,这个词就会Input显示出来。像这样:

在此处输入图片说明

小智 9

将 DropdownButton 更改为 DropdownButtonFormField 并添加此装饰....

              decoration: InputDecoration(
                filled: true,
                fillColor: Hexcolor('#ecedec'),
                labelText: 'Occupation',
                border: new CustomBorderTextFieldSkin().getSkin(),
              ),
Run Code Online (Sandbox Code Playgroud)