只有一个字符的小容器,无法正确居中-颤振

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

只有一个字符的小容器,没有正确居中,填充或不填充设置为0。

如果我减小字体大小,将以居中显示,但默认文本大小为否

Container(
  decoration: BoxDecoration(
    color: Colors.green,
    shape: BoxShape.circle,
  ),
  width: 20.0,
  height: 20.0,
  alignment: Alignment.center,
  padding: EdgeInsets.all(0.0),
  child: Text(
    '+',
  ),
)

Result of green container

更新:与图标相反,字母的行为完全相同。enter image description here

如果我将尺寸从20更改为40:enter image description here

代码

Container(
            width: 40,
            height: 40,
            alignment: Alignment.center,
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              color: Colors.grey,
            ),
            child: RotatedBox(
              quarterTurns: 3,
              child: Icon(
                Icons.expand_less,
                color: Colors.white,
              ),
            ),
          ),
flutter widget containers center
1个回答
1
投票
我无法复制此内容。但是我认为您的默认字体大小对于容器而言太大。您可以尝试将文本包装在

FittedBox中,以使其适合容器:

return Container( decoration: BoxDecoration( color: Colors.green, shape: BoxShape.circle, ), width: 20.0, height: 20.0, alignment: Alignment.center, padding: EdgeInsets.all(0.0), child: FittedBox( child:Text('+') ), );
© www.soinside.com 2019 - 2024. All rights reserved.