【发布时间】:2019-03-04 23:26:57
【问题描述】:
我有一个RichText 和一些TextSpan。我希望其中一个TextSpan 小部件具有背景,因此我使用background: Paint()..color = Colors.redAccent 作为其文本样式。
有没有办法在背景中添加一些额外的红色空间/填充。
这是它目前的样子:
这就是我想要的样子(注意突出显示文本顶部和底部的额外红色):
这是使用的代码:
Scaffold(
appBar: new AppBar(),
body: new RichText(
text: new TextSpan(
text: 'This is a one the lines in the span \n ',
style: TextStyle(fontSize: 15.0, color: Colors.black),
children: <TextSpan>[
new TextSpan(
text: 'This is the second line',
style: new TextStyle(fontWeight: FontWeight.bold)),
new TextSpan(
text: ' background on me ',
style: new TextStyle(
fontWeight: FontWeight.bold,
background: Paint()..color = Colors.redAccent,
)),
new TextSpan(text: ' This is another of the lines in the span!'),
],
),
), // This trailing comma makes auto-formatting nicer for build methods.
)
我尝试在文本样式中添加height,但它不影响背景的高度。
【问题讨论】: