我在 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)
我该怎么做?
谢谢
我不知道你的确切用例 - 但获得你所需的一种方法:
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)
如果你想在 RichText 中使用 textalign 使用WidgetSpan和Text widget
WidgetSpan(
child: Text(
'your text',
textAlign: TextAlign.left,
textDirection: TextDirection.ltr,
),
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30818 次 |
| 最近记录: |