Flutter-如何在弹出菜单中添加关闭图标?

发布于 2025-02-09 17:26:54 字数 1454 浏览 3 评论 0原文

             PopupMenuButton<String>(

                    child: SizedBox(
                      child: ....
                    ),

                    onSelected: (value) {},
                    itemBuilder: (BuildContext context) {

               ///Add a close icon here (to the right) before rendering the list
                      return list!.map((notification) {
                        return custom_popup_menu.PopupMenuItem<String>(
                          value: someValue,
                          child: SizedBox(
                            child: Column(
                              children: [
                                const Divider(
                                  thickness: 1,
                                  color: CustomColor.blue_color,
                                ),
                                Text(
                                  'some text',
                                  style: TextStyle(
                                    fontWeight: (notification.readOn == null)
                                        ? FontWeight.w900
                                        : FontWeight.normal,
                                  ),
                                ),
                              ],
                            ),
                          ),
                        );
                      }).toList();
                    },
                  ),
             PopupMenuButton<String>(

                    child: SizedBox(
                      child: ....
                    ),

                    onSelected: (value) {},
                    itemBuilder: (BuildContext context) {

               ///Add a close icon here (to the right) before rendering the list
                      return list!.map((notification) {
                        return custom_popup_menu.PopupMenuItem<String>(
                          value: someValue,
                          child: SizedBox(
                            child: Column(
                              children: [
                                const Divider(
                                  thickness: 1,
                                  color: CustomColor.blue_color,
                                ),
                                Text(
                                  'some text',
                                  style: TextStyle(
                                    fontWeight: (notification.readOn == null)
                                        ? FontWeight.w900
                                        : FontWeight.normal,
                                  ),
                                ),
                              ],
                            ),
                          ),
                        );
                      }).toList();
                    },
                  ),

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

土豪我们做朋友吧 2025-02-16 17:26:54

您可以在地图上使用Spreed操作员来列出并创建另一个内部列表,包括Close PopupMenuitem。

PopupMenuButton<String?>(
    onSelected: (value) => setState(() => value = value),
    itemBuilder: (context) => [
          PopupMenuItem<String?>(
            child: TextButton(
              onPressed: Navigator.of(context).pop,
              child: Text("close"),
            ),
          ),
          ...["A", "B"]
              .map(
                (e) => PopupMenuItem<String?>(
                  value: e,
                  child: Text(e),
                ),
              )
              .toList(),
        ])

You can include use spreed operator on map to list and create another inner list including close PopupMenuItem.

PopupMenuButton<String?>(
    onSelected: (value) => setState(() => value = value),
    itemBuilder: (context) => [
          PopupMenuItem<String?>(
            child: TextButton(
              onPressed: Navigator.of(context).pop,
              child: Text("close"),
            ),
          ),
          ...["A", "B"]
              .map(
                (e) => PopupMenuItem<String?>(
                  value: e,
                  child: Text(e),
                ),
              )
              .toList(),
        ])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文