[英]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.