简体   繁体   English

如何在 flutter 中将两行文本与一行文本对齐

[英]How to align text with 2 lines with a text of one line in flutter

So, I want the row with a string of 2 lines ("Some long string with 2 lines heres") to be properly aligned with the string of 1 line: ("Name:"), but I want to do this WITHOUT checking the string length.因此,我希望带有 2 行字符串的行(“Some long string with 2 lines heres”)与 1 行字符串正确对齐:(“Name:”),但我想在不检查的情况下执行此操作字符串长度。

This is my code for the row:这是我的行代码:

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,
            ),
      ),
    ),
  ],
);

As for the result I want, here's an image example:至于我想要的结果,这是一个图像示例:

在此处输入图像描述

Use crossAxisAlignment Row parameter to align the text to start crossAxisAlignment: CrossAxisAlignment.start使用crossAxisAlignment Row参数对齐文本以开始crossAxisAlignment: CrossAxisAlignment.start

Solution-解决方案-

       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,
                  ),
                ),
              ),
            ],
          ),

Hope this will help you If you have any doubts ask in comment.希望这会对您有所帮助,如果您有任何疑问,请在评论中提问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM