gpt4 book ai didi

Flutter:是否可以在高度> 1.0 的文本行中设置垂直对齐方式?

转载 作者:行者123 更新时间:2023-12-01 23:12:28 24 4
gpt4 key购买 nike

Figma 中的所有文本都有一定的高度,例如 1.5,但是当我将那个高度 设置为 TextStyle,所有具有新高度的行都与底部对齐。

See picture

如果使用居中对齐 小部件 - 错误的结果。示例在其行中具有底部垂直对齐。就像底部的屏幕截图一样。

[ Text screenshots2

是否可以在 flutter Text wiget 中为每一行设置垂直对齐?或者也许有人有一些有用的提示来解决问题?

    Text(
'Example\nExample',
textAlign: TextAlign.center,
style:TextStyle(
height: 2.5,
fontSize: 20,
),
);

解决方案:

作为user1032613建议,这样的解决方案有帮助。

Result text picture

    final text = 'Example Example\nExample Example';
const double height = 2.5;
const double textSize = 16.0;
const double bottomPadding = (height * textSize - textSize) / 2;
const double baseline = height * textSize - height * textSize / 4;
final Widget textWidget = Container(
color: const Color(0xFFFFFFFF),
padding: const EdgeInsets.only(bottom: bottomPadding),
child: Baseline(
baselineType: TextBaseline.alphabetic,
baseline: baseline,
child: Text(
text,
style: const AppTextStyle(
height: height,
fontSize: textSize,
color: const Color(0xFFaa3a3a),
),
),
),
);

最佳答案

有一个名为 leadingDistribution 的属性可用于此目的:

Text(
'text',
style: TextStyle(
height: 2.0,
leadingDistribution: TextLeadingDistribution.even,
),
)

关于Flutter:是否可以在高度> 1.0 的文本行中设置垂直对齐方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69573547/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com