【问题标题】:Text justify, align文本对齐,对齐
【发布时间】:2020-07-12 04:44:39
【问题描述】:

是否可以使我的文本正常,我的意思是单词之间没有空格? 有没有办法通过分隔它们来包装下一行的单词?

screenshot

desired result

这是我的文本部分代码。

Widget textSection({String leadingTitle, String title, String content, BuildContext context}) {
      return Row(
        children: <Widget>[
          Material(
            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
            color: Colors.red,
            child: Container(
              padding: EdgeInsets.all(5.0),
              child: Text(leadingTitle,
                  style: TextStyle(
                      color: Colors.white,
                      fontWeight: FontWeight.bold,
                      fontSize: 18.0)),
            ),
          ),
          SizedBox(
            width: 10.0,
          ),
          Expanded(
            child: Column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
              children: <Widget>[
                Text(
                  text: content,
                  textAlign: TextAlign.justify,

                  style: TextStyle(
                      fontFamily: 'verdana', color: Colors.black, fontSize: 14), 
                )
              ],
            ),
          )
        ],
      );
    }

【问题讨论】:

  • 您能否更清楚地说明所需的输出应该是什么样的?
  • @JJuice 刚刚添加了欲望输出截图
  • @GenchiGenbutsu 没有textAlign: TextAlign.justify 它看起来像这样 - image

标签: flutter text text-align


【解决方案1】:

将您的代码更改为:

Widget textSection({String leadingTitle, String title, String content, 
BuildContext context}) {
  return Row(
    children: <Widget>[
      Material(
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
        color: Colors.red,
        child: Container(
          padding: EdgeInsets.all(5.0),
          child: Text(leadingTitle,
              style: TextStyle(
                  color: Colors.white,
                  fontWeight: FontWeight.bold,
                  fontSize: 18.0)),
        ),
      ),
      SizedBox(
        width: 10.0,
      ),
      Expanded(
        child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            Text(
              text: content,

              //this was TextAlign.justify
              textAlign: TextAlign.left, // will now left justify your text

              style: TextStyle(
                  fontFamily: 'verdana', color: Colors.black, fontSize: 14), 
            )
          ],
        ),
      )
    ],
  );
}

【讨论】:

  • Peter,您分享的 img 正是您要找的,对吗?如果有,请点赞。谢谢。
猜你喜欢
  • 2015-02-12
  • 2020-05-23
  • 2017-02-17
  • 2011-12-26
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
  • 2015-03-25
  • 2014-08-10
相关资源
最近更新 更多