Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add border around TextSpan in RichText widget

Tags:

flutter

dart

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

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

border around text

like image 825
S.D. Avatar asked Sep 28 '18 11:09

S.D.


1 Answers

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')
                ]))
like image 178
Andrey Turkovsky Avatar answered Nov 08 '22 01:11

Andrey Turkovsky