Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decorate text stroke in Flutter?

Tags:

flutter

How to decorate text stroke in Flutter? It's like -webkit-text-stroke - CSS

like image 605
granoeste Avatar asked Sep 03 '18 08:09

granoeste


People also ask

How do you decorate Text in Flutter?

You do it by applying decoration: TextDecoration. underline to TextStyle of a Text . Show activity on this post. Text( 'Welcome to Flutter', style: TextStyle( fontSize: 24, decoration: TextDecoration.

How do you add an outline to a Text Flutter?

The example below shows you how to add a stroke (or border) to text in Flutter. Screenshot: The code: Scaffold( appBar: AppBar( title: const Text('KindaCode.com'), ), body: Center( child: Stack( children: [ // The text border Text( 'Hi There', style: TextStyle( fontSize: 70, letterSpacing: 5, fontWeight: FontWeight.

How do you add color to Text on Flutter?

Step 1: Locate the file where you have placed the Text widget. Step 2: Inside the Text widget, add the Style parameter and assign the TextStyle widget. Step 3: Inside the TextStyle widget, add the color parameter and set the color of your choice. For example, color: Colors.


2 Answers

Stroke has been possible without workarounds since the addition of foreground paints in TextStyle. An explicit example of stroke under fill bordered text has been added in the TextStyle documentation: https://master-api.flutter.dev/flutter/painting/TextStyle-class.html#painting.TextStyle.6

This example is reproduced here:

enter image description here

Stack(   children: <Widget>[     // Stroked text as border.     Text(       'Greetings, planet!',       style: TextStyle(         fontSize: 40,         foreground: Paint()           ..style = PaintingStyle.stroke           ..strokeWidth = 6           ..color = Colors.blue[700],       ),     ),     // Solid text as fill.     Text(       'Greetings, planet!',       style: TextStyle(         fontSize: 40,         color: Colors.grey[300],       ),     ),   ], ) 

Stroke by itself is possible by removing the Stack and just using the first stroke Text widget by itself. The stroke/fill order can also be adjusted by swapping the first and second Text widget.

like image 75
Gary Qian Avatar answered Oct 03 '22 21:10

Gary Qian


I was also looking for this, wasn't able to find it. But I did find a workaround using 4 shadows in the TextStyle:

Text("Border test",     style: TextStyle(       inherit: true,       fontSize: 48.0,       color: Colors.pink,       shadows: [         Shadow( // bottomLeft           offset: Offset(-1.5, -1.5),           color: Colors.white         ),         Shadow( // bottomRight           offset: Offset(1.5, -1.5),           color: Colors.white         ),         Shadow( // topRight           offset: Offset(1.5, 1.5),           color: Colors.white         ),         Shadow( // topLeft           offset: Offset(-1.5, 1.5),           color: Colors.white         ),       ]     ), ); 

I also opened an Issue on GitHub: https://github.com/flutter/flutter/issues/24108

like image 42
PieterAelse Avatar answered Oct 03 '22 20:10

PieterAelse