[英]How to align text with 2 lines with a text of one line in flutter
因此,我希望带有 2 行字符串的行(“Some long string with 2 lines heres”)与 1 行字符串正确对齐:(“Name:”),但我想在不检查的情况下执行此操作字符串长度。
这是我的行代码:
Row(
children: <Widget>[
Text(
title,
style: Theme.of(context).textTheme.headline6.copyWith(height: 1.24),
),
Spacer(),
Container(
width: 242.0,
alignment: Alignment.bottomRight,
child: Text(
text,
textAlign: TextAlign.end,
maxLines: 2,
style: Theme.of(context).textTheme.bodyText1.apply(
color: kGrey,
),
),
),
],
);
至于我想要的结果,这是一个图像示例:
使用crossAxisAlignment
Row
参数对齐文本以开始crossAxisAlignment: CrossAxisAlignment.start
解决方案-
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
title,
style: Theme.of(context)
.textTheme
.headline6
.copyWith(height: 1.24),
),
Spacer(),
Container(
width: 242.0,
alignment: Alignment.bottomRight,
child: Text(
text,
textAlign: TextAlign.end,
maxLines: 2,
style: Theme.of(context).textTheme.bodyText1.apply(
color: kGrey,
),
),
),
],
),
希望这会对您有所帮助,如果您有任何疑问,请在评论中提问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.