flutter - 文本中的空格 - Flutter
问题描述
在 Flutter 中使用 Unicode 文本时,每个字符中似乎都有很多空格,这使得对齐变得困难。在下面的代码和图片中,我试图让 35m 坐在十字箭头上,中间没有空格。我还试图让三颗星在开始时与starburst这个词垂直居中对齐,然后将(35m和箭头)、starburst和你的星星都居中对齐,彼此垂直对齐。
Scaffold(
body: SafeArea(
child: Column(
children: [
Row(
children: [
Text(
'\u{2605}' * 3,
style: TextStyle(
fontSize: 18.0,
),
),
Text(
'Starburst',
style: TextStyle(
fontSize: 28.0,
),
),
Column(
children: [
Text(
'35m',
style: TextStyle(
fontSize: 18.0,
),
),
Text(
'\u{2194}',
style: TextStyle(fontSize: 35.0),
),
],
)
],
),
],
),
),
);
解决方案
您可以根据您的 UI 规范使用Stack
而不是对齐文本:Column
使用列输出:
使用堆栈输出:
完整代码:
return Scaffold(
body: SafeArea(
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'\u{2605}' * 3,
style: TextStyle(
fontSize: 18.0,
),
),
Text(
'Starburst',
style: TextStyle(
fontSize: 28.0,
),
),
// SizedBox(width: 5.0),
Container(
width: 50.0,
child: Center(
child: Stack(
children: [
Positioned(
top: 4,
child: Text(
'35m',
style: TextStyle(
fontSize: 18.0,
),
),
),
Text(
'\u{2194}',
style: TextStyle(fontSize: 40.0),
),
],
),
),
),
],
),
],
),
),
);
您可能需要Stack
稍微调整小部件的孩子,但我希望这个答案能给出这个想法。
推荐阅读
- amazon-web-services - 为 EC2 Windows 机器收集事实 - 错误“ShellModule”对象没有属性“ECHO”
- asp.net-core - ASP.NET Core 3.1 - signalR 集成测试 - 带有身份验证的 webhost 固定装置
- java - Mapstruct:嵌套对象的自定义映射方法
- python - 如何打印分数线以上的分数和下一个分数线以下的分数?
- css - MaterialUI:为什么在 Select 组件上设置背景颜色会隐藏 InputLabel 文本,我该如何避免它发生?
- amazon-web-services - AWS:certbot-auto 不再支持您的系统
- mysql - 如何更改 MySQL 中的 TIMESTAMPDIFF 日期格式?
- terraform - 我该如何做尺寸块“动态”?
- javascript - (鼠标离开)时保持(点击)效果
- elasticsearch - Timelion:如何计算拆分组