颤振富文本分离对齐

ALE*_*ANO 8 flutter

我在 flutter 中看到了这段富文本代码:

  return Row(
        children: <Widget>[
          ?
          Container(
            child: RichText(
              text: TextSpan(
                text: "Hello",
                style: TextStyle(fontSize: 20.0,color: Colors.black),
                children: <TextSpan>[
                  TextSpan(text:"Bold"),
                    style: TextStyle( fontSize: 10.0, color: Colors.grey),

                  ),

                ],
              ),
            ),
          )
Run Code Online (Sandbox Code Playgroud)

这个印刷品

Hellobold 
Run Code Online (Sandbox Code Playgroud)

但我需要将两个文本分开,一个向左,另一个向右,就像这样

Hello                               bold
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

谢谢

anm*_*ail 6

我不知道你的确切用例 - 但获得你所需的一种方法:

Row(
      children: <Widget>[
                Expanded(
                  child: RichText(
                      text: TextSpan(children: [
                    TextSpan(text: 'Singh', style: TextStyle(fontSize: 22.0,color: Colors.grey))
                  ])),
                ),
                RichText(
                    text: TextSpan(children: [
                      TextSpan(text: 'Kaur', style: TextStyle(fontSize: 28.0,color: Colors.redAccent))
                    ])),
              ],
            ),
Run Code Online (Sandbox Code Playgroud)


Kar*_*mal 5

如果你想在 RichText 中使用 textalign 使用WidgetSpanText widget

WidgetSpan(
  child: Text(
    'your text',
    textAlign: TextAlign.left,
    textDirection: TextDirection.ltr,
  ),
),
Run Code Online (Sandbox Code Playgroud)