繁体   English   中英

如何在 Flutter 中自定义下拉按钮?

[英]How can I customize a Dropdown Button in Flutter?

如何在 Flutter 中存档此设计?

我需要将下拉按钮自定义为以下屏幕截图:

在此处输入图像描述

如何为选定项目设置样式,为未选定项目设置另一个样式,但不更改下拉菜单上方 label 的样式?

如果有人可以提供帮助,那就太棒了

尝试这个:

            PopupMenuButton<MenuItems>(
              child: Row(
                children: [
                  Text('Show Menu'),
                  Icon(
                    Icons.expand_more,
                    color: Colors.grey,
                  ),
                ],
              ),
              onSelected: (MenuItems result) {
                setState(() {
                  selection = result;
                });
              },
              itemBuilder: (BuildContext context) =>
                  <PopupMenuEntry<MenuItems>>[
                PopupMenuItem<MenuItems>(
                  value: MenuItems.one,
                  child: Row(
                    children: [
                      MenuItems.one == selectedItem
                          ? Row(
                              children: [
                                Container(
                                  width: 3,
                                  height: 16,
                                  color: Colors.red,
                                ),
                                SizedBox(
                                  width: 8,
                                ),
                              ],
                            )
                          : Container(),
                      Text(
                        'One',
                        style: TextStyle(
                          color: (MenuItems.one == selectedItem)
                              ? Colors.red
                              : null,
                        ),
                      ),
                    ],
                  ),
                ),
                PopupMenuItem<MenuItems>(
                  value: MenuItems.two,
                  child: Row(
                    children: [
                      MenuItems.two == selectedItem
                          ? Row(
                              children: [
                                Container(
                                  width: 3,
                                  height: 16,
                                  color: Colors.red,
                                ),
                                SizedBox(
                                  width: 8,
                                ),
                              ],
                            )
                          : Container(),
                      Text(
                        'Two',
                        style: TextStyle(
                          color: (MenuItems.two == selectedItem)
                              ? Colors.red
                              : null,
                        ),
                      ),
                    ],
                  ),
                ),
                PopupMenuItem<MenuItems>(
                  value: MenuItems.three,
                  child: Row(
                    children: [
                      MenuItems.three == selectedItem
                          ? Row(
                              children: [
                                Container(
                                  width: 3,
                                  height: 16,
                                  color: Colors.red,
                                ),
                                SizedBox(
                                  width: 8,
                                ),
                              ],
                            )
                          : Container(),
                      Text(
                        'Three',
                        style: TextStyle(
                          color: (MenuItems.three == selectedItem)
                              ? Colors.red
                              : null,
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ],
        ),

暂无
暂无

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

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