如何将TextDecoration添加到DropdownButton

时间:2020-06-23 18:58:06

标签: flutter dart

我成功添加了多个下拉菜单,但我希望每个TextFormField都具有一个InputDecoration,因此我可以保持用户界面的一致性,并显示从下拉菜单中选择之后的下拉菜单。

TextFormField(
  decoration: InputDecoration(
    labelText: 'Action'
  ),
);

显然,发布图像需要10声望。 (我的意思是这样)

TextFormField with labelText set to Action

给我一​​个漂亮的TextFormField ...但是我想为下拉菜单使用相同类型的接口,在这里我可以给它一个InputDecoration。现在,选择完后,我希望在DropdownButton上方具有相同的'labelText'。

My DropdownButton has a nice look and feel before I've entered the value

But afterwards it doesn't have a reminder for what the dropdown was

I was hoping for something along these lines, but even this quickly edited version has a smaller space between the line and the selected text.

我尝试创建TextDecorator / TextDecoration的mixin并将其放入现有的DropdownButton类中,但是我对这种语言仍然是个超级菜鸟,只是了解了mixin,但似乎对它没有帮助。如何将TextDecoration从TextFormField添加到DropdownButton上?

1 个答案:

答案 0 :(得分:0)

您似乎可以使用 DropdownButtonFormField
做这样的事情:

DropdownButtonFormField(
  decoration: InputDecoration(labelText: 'Action'),
  items: [
    DropdownMenuItem(child: Text('Action1')),
    DropdownMenuItem(child: Text('Action2'),)
  ],
  onChanged: (value){
    print(value);
  },
),