flutter - 只有一个字符的小容器没有正确居中 - Flutter
问题描述
只有一个字符的小容器没有正确居中,有或没有填充设置为 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(
'+',
),
)
代码
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,
),
),
),
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,
),
),
),
),
解决方案
我无法重现这一点。但我假设您的默认字体大小对于容器来说太大了。您可以尝试将 Text 包装在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('+')
),
);
推荐阅读
- sql - SQL Server:从字符串转换日期和/或时间超过 12 点时转换失败
- python - 使用占位符将数组大小调整为不可能的形状
- sql - 将一组行转换为sql中的新列
- python - 梯度不会随着步骤而改变 - Tensorflow
- r - ggplot - 带有自由缩放 facet_wrap 的 geom_text
- c# - 如何自动计算/更新维护表中的到期日
- python - 在 pycharm 2018 中运行 Growing Self-Organizing Map 的 github 实现失败
- druid - 当我们对 daliy 和 row 数据运行相同的查询时,德鲁伊计数不同
- javascript - 来自 Socketio 事件的 Redux 调用调度
- javascript - Compile typescript lib to es2015 and CommonJs modules