【问题标题】:How do I add TextDecoration(s) to a DropdownButton如何将 TextDecoration(s) 添加到 DropdownButton
【发布时间】:2020-10-13 22:29:14
【问题描述】:

我成功添加了多个下拉菜单,但我想要一个 TextFormField 的 InputDecoration,这样我可以保持用户界面一致,并在您从下拉菜单中选择后显示下拉菜单的内容。

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

显然我需要 10 声望才能发布图片。 (我的意思是有道理)

TextFormField with labelText set to Action

给了我一个好看的 TextFormField... 但是我想要我的下拉菜单使用相同类型的界面,我可以在其中给它一个 InputDecoration。现在,在我选择了 DropdownButton 之后,我想要在我的 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 类中,但我仍然是该语言的超级菜鸟,并且刚刚了解了 mixins,它似乎没有帮助。如何将 TextFormField 中的 TextDecoration 添加到 DropdownButton 上?

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    看起来你可以使用 DropdownButtonFormField
    做这样的事情:

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

    【讨论】:

    • 天哪,谢谢,太简单了!正是我所希望的!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-13
    • 2020-07-26
    • 2021-11-08
    • 1970-01-01
    • 2015-12-25
    • 2017-01-27
    相关资源
    最近更新 更多