圆形图标弹出菜单的正确波纹效果形状

时间:2019-10-21 10:24:09

标签: flutter material-design popupmenu

在Flutter中,我想为图标按钮设置带有圆形边框的样式,并且还希望“材质波纹”效果正常工作,以便使波纹效果包含在圆圈中。在下面的代码中,第一个按钮可以正常工作。在第二个(弹出)按钮中,波纹效果延伸到围绕按钮的正方形,而不是局限于圆形边框。

The second button

MaterialApp(
  home: Scaffold(
    body: Center(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          Container(
            decoration: BoxDecoration(
              border: Border.all(color: Colors.black, width: 2),
              shape: BoxShape.circle,
            ),
            child: MaterialButton(
              minWidth: 0,
              padding: EdgeInsets.all(0.0),
              child: Padding(
                padding: EdgeInsets.all(11.0),
                child: Icon(Icons.home, size: 27.0),
              ),
              shape: CircleBorder(),
              onPressed: () {},
            ),
          ),
          PopupMenuButton<String>(
            onSelected: (String action) {},
            child: Container(
              decoration: BoxDecoration(
                border: Border.all(color: Colors.black, width: 2),
                shape: BoxShape.circle,
              ),
              child: Padding(
                padding: EdgeInsets.all(11.0),
                child: Icon(Icons.menu, size: 27.0),
              ),
            ),
            itemBuilder: (BuildContext context) => [
              PopupMenuItem<String>(child: ListTile(title: Text('Log Out'))),
            ],
          ),
        ],
      ),
    ),
  ),
);

有没有办法使弹出按钮正常工作?

1 个答案:

答案 0 :(得分:1)

您需要同时使用ClipRRectMaterial

ClipRRect(
  borderRadius: BorderRadius.circular(24),
  child: Material(
    color: Colors.transparent,
    child: PopupMenuButton<String>(
    ...

PopupMenuButtonchild包装InkWell,由于某些原因,除非也将其包装在Material中,否则它们不会被裁剪。