在RichText小部件中的TextSpan周围添加边框 [英] Add border around TextSpan in RichText widget

查看:430
本文介绍了在RichText小部件中的TextSpan周围添加边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 RichText 小部件,其中包含一些 TextSpan 。我想在 TextSpan 小部件周围放置边框。

I have a RichText widget that contains some TextSpan. Around a TextSpan widget I want to place a border around it.

RichText(
  text: TextSpan(
    style: textStyle,
    children: [ ], // code has more TextSpan widgets as children
  ),

这是我要在Flutter中实现的效果的示例。

This is an example of the effect I am trying to achieve in Flutter.

推荐答案

Paint paint = Paint()
  ..color = Colors.blue
  ..style = PaintingStyle.stroke
  ..strokeCap = StrokeCap.round
  ..strokeWidth = 2.0;

RichText(
                    text: TextSpan(children: [
                  TextSpan(text: '123'),
                  TextSpan(text: '456', style: TextStyle(background: paint)),
                  TextSpan(text: '789')
                ]))

这篇关于在RichText小部件中的TextSpan周围添加边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆