简体   繁体   English

如何在 Flutter Web 的下拉菜单中添加标题?

[英]How to add a title to a drop down menu in Flutter Web?

I'm currently working with Flutter web and I'm trying to achieve the following:我目前正在使用 Flutter web,我正在努力实现以下目标:

DropdownMenu下拉式菜单

I can't set a title for the dropdown menu, only add the title as an item in the list.我无法为下拉菜单设置标题,只能将标题添加为列表中的一个项目。

I tried what Firas Krifa proposed and I got the following result:我尝试了 Firas Krifa 的建议,得到以下结果:

Result in small web size导致网页尺寸变小

Result in 4K size结果为 4K 大小

Normal web size(FULL HD)正常网页尺寸(全高清)

I don't know why in the small size the dropdownmenu appears at the left of the dropdownbutton and the 4k size appears at the right.我不知道为什么在小尺寸中,下拉菜单出现在下拉按钮的左侧,而 4k 尺寸出现在右侧。 Also on the normal size it appears on the title, while what I want is that it drops right under the title.同样在正常大小上,它出现在标题上,而我想要的是它正好在标题下。

The widgets DropdownButtonHideUnderline and Theme will help control how the dropdown looks in the title of the AppBar小部件DropdownButtonHideUnderlineTheme将有助于控制下拉菜单在AppBar标题中的外观

https://material.io/guidelines/layout/structure.html#structure-app-bar https://material.io/guidelines/layout/structure.html#structure-app-bar

new AppBar(
  title: new Theme(
      child: new DropdownButtonHideUnderline(
      child: new DropdownButton<String>(
        value: _value,
        items: <DropdownMenuItem<String>>[
          new DropdownMenuItem(
            child: new Text('My Page'),
            value: 'one',
          ),
        ], 
        onChanged: (String value) {
          setState(() => _value = value);
        },
      ),
    ), 
    data: new ThemeData.dark(),
  ),
),


  


Try this尝试这个

new DropdownButton<String>(
  items: <String>['A', 'B', 'C', 'D'].map((String value) {
    return new DropdownMenuItem<String>(
      value: value,
      child: new Text(value),
    );
  }).toList(),
  onChanged: (_) {},
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM