CodeBlanks Logo Icon CodeBlanks

TextStyle

Learn to set font, color and size with TextStyle.

TextStyle

TextStyle is the object that controls the font formatting of the Text widget. fontSize sets the size, color the color, and fontWeight the thickness. An instance of TextStyle is passed to the Text's style parameter.

Text(
  'Başlık',
  style: TextStyle(
    fontSize: 24,
    color: Colors.blue,
    fontWeight: FontWeight.bold,
  ),
)

fontSize, color, fontWeight

fontSize sets the font size in pixels (default 14). color takes a color from the Colors class (Colors.red, Colors.blue). fontWeight sets a thickness between FontWeight.w300 and FontWeight.w900; FontWeight.bold is a common choice.

Text(
  'Vurgulu',
  style: TextStyle(
    fontSize: 20,
    color: Colors.red,
    fontWeight: FontWeight.bold,
  ),
)

Practice Print TextStyle info

In main, print two lines with print: fontSize boyut and color renk.

Starter code

main.dart
void main() {
  // iki satır yazdır:
  // fontSize boyut
  // color renk

}

Sample solution

main.dart
void main() {
  print('fontSize boyut');
  print('color renk');
}

Expected output

fontSize boyut
color renk

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What does TextStyle control?

  • Text formatting Correct answer
  • Text deletion
  • Text position
  • Text rotation

Explanation: TextStyle controls text formatting via fontSize, color and fontWeight.

2 Set text color

Question
style: TextStyle(
  fontSize: 18,
  ____: Colors.blue,
),
Answer
style: TextStyle(
  fontSize: 18,
  color: Colors.blue,
),

Explanation: The color parameter sets the text color inside TextStyle.

3 TextStyle concepts

Term Meaning
TextStyle Font formatting object
fontSize Font size (pixels)
color Text color
fontWeight Font weight

All lessons in Beginner