首页 > 解决方案 > 带有 IconButton 的 CircleAvatar 未居中

问题描述

我想将 CircleAvatar 中的按钮居中,但对于较小的半径,它似乎没有正确居中。

                 CircleAvatar(
                    backgroundColor: Colors.blue,
                    radius: 16,
                    child: IconButton(
                        icon: Icon(Icons.add),
                        color: Colors.white,
                        onPressed: () {

                          }
                        }),
                  ),

这是它的样子:

在此处输入图像描述

标签: flutter

解决方案


IconButton 有一些默认填充,通过删除默认填充来解决问题。检查下面的代码,它工作得很好。

CircleAvatar(
          backgroundColor: Colors.blue,
          radius: 16,
          child: IconButton(
            // remove default padding here
            padding: EdgeInsets.zero,
            icon: Icon(Icons.add),
            color: Colors.white,
            onPressed: () {},
          ),
        ),

代码输出: 在此处输入图像描述


推荐阅读