加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

dart – 在RichText小部件中为TextSpan背景添加额外的填充

发布时间:2020-12-14 14:49:40 所属栏目:百科 来源:网络整理
导读:我有一个带有一些TextSpan的RichText.我希望其中一个TextSpan小部件有背景,所以我使用了背景:Paint().. color = Colors.redAccent作为其文本样式. 有没有办法在背景中添加一些额外的红色空间/填充. 这是它目前的样子: 这就是我想要它的样子(注意突出显示文
我有一个带有一些TextSpan的RichText.我希望其中一个TextSpan小部件有背景,所以我使用了背景:Paint().. color = Colors.redAccent作为其文本样式.

有没有办法在背景中添加一些额外的红色空间/填充.

这是它目前的样子:

before padding on text

这就是我想要它的样子(注意突出显示文本顶部和底部的额外红色):

after padding on text (desired)

这是使用的代码:

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.
)

我尝试在文本样式中添加高度,但它不会影响背景的高度.

解决方法

相当丑陋的解决方案,但我没有找到其他(

TextStyle(fontWeight: FontWeight.bold,background: Paint()..color = Colors.redAccent
    ..strokeWidth = 16.5
    ..style = PaintingStyle.stroke,)

strokeWidth必须足够大才能覆盖文本的高度.在我的情况下,16.5是最小的合适值

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读