Flutter 只有一个字符的小容器没有正确定心-颤振
只有一个字符的小容器没有正确居中,带或不带填充设置为0 如果减小字体大小,将以居中显示,但默认文本大小为否Flutter 只有一个字符的小容器没有正确定心-颤振,flutter,widget,containers,center,Flutter,Widget,Containers,Center,只有一个字符的小容器没有正确居中,带或不带填充设置为0 如果减小字体大小,将以居中显示,但默认文本大小为否 Container( decoration: BoxDecoration( color: Colors.green, shape: BoxShape.circle, ), width: 20.0, height: 20.0, alignment: Alignment.center, padding: EdgeInsets.all(0.0), ch
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(
'+',
),
)
更新:
与图标相反,字母的行为完全相同。
如果我将大小从20更改为40:
代码
更新2:配有图标的已安装工程:
我无法复制这个。但是我假设您的默认字体大小对于容器来说太大了。您可以尝试将文本包装在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('+')
),
);
我无法复制您的问题。您的代码的工作方式与预期完全相同。屏幕截图:您的问题可能来自代码中的其他内容。可能是因为你的绿点是一个装饰,你的文本是一个小部件,它们受到不同的影响。我能查到什么线索吗?我不相信for you works Fine它可能有助于在您使用它的地方共享更多的周围代码。这稍微增加了一点加号,但没有完全集中。这是FittedBox复选框“flatter doctor”的结果。你在哪根树枝上?我在想。。。不会是字体吧?我用字体Futura中。。。我目前的分支是Channel stable,v1.12.13+修补程序.8,在美国微软Windows[Version 10.0.18362.657]上
Container(
width: 20,
height: 20,
alignment: Alignment.center,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).textTheme.caption.color,
),
child: FittedBox(
child: RotatedBox(
quarterTurns: 3,
child: Icon(
Icons.expand_less,
color: Theme.of(context).primaryColor,
),
),
),
),
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('+')
),
);