Home > Back-end >  How to give border/background to a Text in Flutter?
How to give border/background to a Text in Flutter?

Time:12-14

I want to give my text a border or background. Just a simple text in red with a black border around it.

See the following image as inspiration:

enter image description here

CodePudding user response:

Just look up the TextStyle class in the flutter Documentation. On Borders an Stroke you'll find your answer I believe.

Flutter Documentation

CodePudding user response:

Please refer to outlined_text package here

You can also try this https://pub.dev/packages/bordered_text

CodePudding user response:

I found the answer in Flutter Documentation

There's no border property but yes you can use two overlapping Texts to do the job. Here's the code

Stack(
  children: <Widget>[
    // Stroked text as border.
    Text(
      'WHO',
      style: TextStyle(
        fontSize: 40,
        foreground: Paint()
          ..style = PaintingStyle.stroke
          ..strokeWidth = 6
          ..color = Colors.grey,
      ),
    ),
    // Solid text as fill.
    Text(
      'WHO',
      style: TextStyle(
        fontSize: 40,
        color: Colors.red,
      ),
    ),
  ],
)
  • Related