support@codebucket.net

Discussions about Flutter Text

Discussions about Flutter Text

Nafis Hasrat Arnob | September 25, 2022

Hello Developers,

In this tutorial, I will try to discuss Flutter Text. If you do not know about Flutter Text, this tutorial is for you.

Text widget is used to display strings in the application. Text widgets have many attributes. Other than the String itself all other attributes are optional. Here is a list of useful attributes of the Text widget.

 

  • data = the string that will be shown using Text. It is the only compulsory attribute.
  • textStyle = set style of the text
  • textAlign = used to specify how the text is aligned.
  • overflow = set what happens when the String size exceeds the allocated size for the Text widget.
  • softWrap = determines whether the Text widget shows all content when there is not enough space available.
  • maxLine = set the maximum number of lines of the Text 

 

Style parameter is one of them. We can style the text as per our needs using TextStyle(). Text can hold a single style. TextStyle() holds multiple optional attributes such as font size, color, background color, font weight, letter spacing, word spacing, etc. Here is a list of useful attributes and what it does. 

 

  • fontSize = Set the size of the text
  • fontWeight = set the thickness of the text
  • color = set the color of the text
  • backgroundColor = set background color
  • fontFamily = change font family of the text
  • letterSpacing = determine the spacing between characters
  • wordSpacing = determine the spacing between words
  • fontStyle = set text style to bold or italic

 

Let's see the code for a better understanding:

 

Text(
          'Hello World!',
          overflow: TextOverflow.ellipsis,
          maxLines: 3,
          softWrap: true,
          textAlign: TextAlign.justify,
          style: TextStyle(
            color: Colors.green,
            fontSize: 25,
            fontWeight: FontWeight.bold,
            letterSpacing: 2
          ),
        ),
      ),

 

Hope this might help you in the development journey.

 

Read More: Want to know about Flutter Container?

 

Nafis Hasrat Arnob

Nafis Hasrat Arnob

Information Analyst

I am a Flutter developer working for a reputed company in Bangladesh. I am trying my best to gain proficiency in Software Development. I am also interested in Artificial Intelligence, Machine Learning, and Computer Vision.