In this post, I will be introducing a very easy method to set a space between Flutter text and underline. I will be implementing the space between Flutter text and underline using a very simple example so you can also easily implement it in your own Flutter code. So let’s jump right into implementing space between Flutter text and underline.
What is Space Between Flutter Text And Underline?
Space between Flutter text and underline as the name suggests, it is the distance between the Flutter text and underline. When we define a Flutter text widget and give it an underline then there is not much of a distance/space between the text and underline and if we make the underline a little thick(heighted) then the Flutter text and underline will be attached and will look very bad.
Let’s understand it using a proper Flutter code implementation. First we will see what the default space between Flutter text and underline looks like, then we change it using a simple method.
Default Space Between Flutter Text And Underline
To see the default space between Flutter text and underline, we have to define a Flutter text widget with some text and an underline. If you want to know how to properly implement Flutter text underline then underline. See the below code:
Text('Default space between text and underline', style: TextStyle(decoration: TextDecoration.underline))

Default Space Between Text And Thick Underline
Let’s now make the underline a bit thick and then see what the default space between Flutter text and underline will look. To make the Flutter text underline thick, we have to use the decoration thickness constructor of the text style class. This constructor takes a double(decimal) value but integer will also work(it will convert it automatically). For demonstration, we have passed it a value of 3. See the below code:
Text( 'Space between text and thick underline', style: TextStyle( decoration: TextDecoration.underline, decorationThickness: 3))

Implementing Space Between Flutter Text And Underline(All Steps)
In order to implement it, we will use a simple trick. See the below steps:
Step 1: Give Shadow To The Text
shadows: [Shadow(color: Colors.black45, offset: Offset(0, -10))]

Step 2: Give Custom Colors To The Underline
decorationColor: Colors.grey

Step 3: Make The Flutter Text Color Transparent
color: Colors.transparent

Now the final step is to make the color of the Flutter text transparent. For that we have to use the color constructor of the text style class and pass it Colors.transparent. In the image above you can see that the text color is transparent and cannot be seen. We also have made the shadow color complete from Colors.black45 to Colors.black. You can leave the thickness of the underline or you can change it depends on the requirements of your Flutter app project.
You can see that we have successfully implemented a space between Flutter text and underline. The text is actually a shadow in the above image but still it works. Hope you now have a complete understanding of how to implement space between Flutter text and underline. Don’t hesitate to ask in the comment section if you still have any doubts related to the implementation of space between Flutter text and underline. I would love to answer all.
The complete source code for the above implemented space between Flutter text and underline is given in the below section.
Space Between Flutter Text And Underline Implementation Source Code
import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Homepage(), ); } } class Homepage extends StatelessWidget { @override Widget build(BuildContext context) { return SafeArea( child: Scaffold( body: Center( child: Padding( padding: const EdgeInsets.all(15), child: Text('Custom space between text and thick underline', style: TextStyle( color: Colors.transparent, decorationColor: Colors.grey, shadows: [Shadow(color: Colors.black, offset: Offset(0, -10))], decoration: TextDecoration.underline, decorationThickness: 3)), )))); } }
Conclusion
To conclude this post, now you have a complete implementation knowledge of how to use and implement space between Flutter text and underline. Don’t hesitate to share your valuable thoughts about this post. Thanks for reading this article.