如何制作弹出菜单按钮(如浮动操作按钮?

问题描述 投票:0回答:1

我想在appBar上有一个Button,当我单击它时,它像FAB的Floating Action一样显示给我三个另外的按钮,但它位于appBar上。

像在右上角“”

我尝试了很多选项,例如浮动操作按钮,IconButton和PopupMenuButton。

这是我最好的PopupMenuButton解决方案:

PopupMenuButton<Choice>(
           
            icon: Icon(
                MyIcon.edit,
               
                size: 35, color: Colors.white, 
              ),
            //  child: IconButton( icon: Icon(
            //     MyIcon.edit,
            //     // color: Colors.white,
            //     size: 35, color: Colors.white, 
            //   ),onPressed: _buildLayoutContainer,
            //  ),
              elevation: 0,
              onSelected: choiceAction,
              itemBuilder: (BuildContext context) {
                return choices.map((Choice choice) {
                  if (choice.text == null) {
                    return PopupMenuItem<Choice>(
                      value: choice,
                      child: Row(
                        children: <Widget>[
                          SizedBox(
                            height: 50,
                            width: 1,
                          ),
                        ],
                      ),
                    );
                  } else {
                    return PopupMenuItem<Choice>(
    
                    
                      value: choice,
                      child: Row(
                       mainAxisSize: MainAxisSize.min,
                        mainAxisAlignment: MainAxisAlignment.end,
                         
                        children: <Widget>[
                          SizedBox(
                            width: 103,
                          ),
                          choice.text,
                          SizedBox(
                            width: choice.width,
                          ),
                          Column(
                            children: <Widget>[
                              IconButton(
                                icon: choice.icon,
                                onPressed: () => _selectTransaction(context),
                              ),
                              SizedBox(
                                height: choice.height,
                              )
                            ],
                          ),
                         
                        ],
                        
                      ),
                    );
                  }
                }).toList();
              }),
我没有找到一种方法可以将图标与右上角的编辑按钮垂直对齐,并且无法像在抽屉小部件中或图1中那样将背景高高地聚焦在这三个图标上。这是它的外观:“”

是否有一种更优雅的方法来制作这种按钮,尤其是通过背景和对齐来解决这两个问题?

我很想听听一些建议:)

flutter flutter-layout
1个回答
1
投票

PopupMenuButton支持offset,可以使用offset调整显示位置您可以参考https://medium.com/flutteropen/widgets-14-popupmenubutton-1f1437bbdce2

代码段

PopupMenuButton<Choice>(
        offset: Offset(100, 100), 
        icon: Icon(

参考文件中的示例

Widget _offsetPopup() => PopupMenuButton<int>(
          itemBuilder: (context) => [
                PopupMenuItem(
                  value: 1,
                  child: Text(
                    "Flutter Open",
                    style: TextStyle(
                        color: TEXT_BLACK, fontWeight: FontWeight.w700),
                  ),
                ),
                PopupMenuItem(
                  value: 2,
                  child: Text(
                    "Flutter Tutorial",
                    style: TextStyle(
                        color: TEXT_BLACK, fontWeight: FontWeight.w700),
                  ),
                ),
              ],
          icon: Icon(Icons.library_add),
          offset: Offset(0, 100),
        );
© www.soinside.com 2019 - 2024. All rights reserved.