Learn/Core Widgets/Text & Styling

Text & Styling

Display and style text in Flutter

4 min~5 min read+25 FX

You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.

Table of Contents

  1. 1. TextStyle Properties
  2. 2. RichText for Mixed Styles
  3. 3. Text Hierarchy Strategy
  4. 4. This Lesson In Simple Words
  5. 5. Your level focus
  6. 6. One practical habit
  7. 7. Deep Understanding Guide
  8. 8. Why this lesson matters
  9. 9. Study flow for better retention
  10. 10. Quick Glossary

Having trouble? AI is here to help

Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.

Use the AI button at the bottom of the screen

Text Widget

The Text widget is one of the most commonly used widgets in Flutter. It displays a string of text on the screen and gives you full control over its appearance through the TextStyle class.

dart
1// --- Simple Text ---
2Text('Hello World')
3
4
5// --- Styled Text ---
6Text(
7 'Styled Text',
8 style: TextStyle(
9 fontSize: 24, // Text size
10 fontWeight: FontWeight.bold, // Bold text
11 color: Colors.blue, // Text color
12 letterSpacing: 2, // Space between letters
13 decoration: TextDecoration.underline, // Add underline
14 ),
15)
16
17
18// --- Handling Long Text ---
19Text(
20 'This is a very long text that might overflow',
21 maxLines: 2, // Max 2 lines
22 overflow: TextOverflow.ellipsis, // Show ... if too long
23 textAlign: TextAlign.center, // Center the text
24)

TextStyle Properties

PropertyExamplePurpose
fontSize24Text size
fontWeightFontWeight.boldThickness
colorColors.redText color
fontFamily'Roboto'Custom font
letterSpacing2.0Space between letters
height1.5Line height

RichText for Mixed Styles

When you need different colors, sizes, or weights within a single line of text, use the RichText widget or the Text.rich shorthand.

dart
1// --- RichText: Multiple Styles in One Text ---
2// Use when you need different colors/styles in same line
3
4RichText(
5 text: TextSpan(
6 // Default style for all text
7 style: TextStyle(color: Colors.black),
8
9 // Children with different styles
10 children: [
11 TextSpan(text: 'Hello '), // Normal
12 TextSpan(
13 text: 'Flutter', // Bold & Blue
14 style: TextStyle(
15 fontWeight: FontWeight.bold,
16 color: Colors.blue,
17 ),
18 ),
19 TextSpan(text: '!'), // Normal
20 ],
21 ),
22)
23
24
25// --- Shorter way with Text.rich ---
26Text.rich(
27 TextSpan(
28 children: [
29 TextSpan(text: 'Price: '), // Normal text
30 TextSpan(
31 text: '$99', // Bold price
32 style: TextStyle(fontWeight: FontWeight.bold),
33 ),
34 ],
35 ),
36)

Pro Tip

💡 Pro Tip

Use `Theme.of(context).textTheme.headlineMedium` to get consistent text styles across your app instead of hardcoding values. This keeps your typography uniform and easy to update.

Text Hierarchy Strategy

Good UI typography is not random styling. Build a clear hierarchy:

  • Heading: strongest size and weight
  • Subheading: medium emphasis
  • Body: readable default text
  • Caption/helper: smaller supporting text

When hierarchy is consistent, users scan faster and understand content structure without effort.

Text Quality Checklist

  • Contrast is high enough for comfortable reading.
  • Long text has maxLines and overflow handling where required.
  • Font sizes are consistent with theme-based tokens.
  • Important actions are not communicated by color alone.

This Lesson In Simple Words

Display and style text in Flutter. This lesson adds one more building block for creating stable and user-friendly Flutter apps.

Your level focus

Build confidence with basics first; speed comes later.

One practical habit

After reading, rewrite the concept in your own words and apply it in a tiny runnable sample.

Deep Understanding Guide

Why this lesson matters

Each lesson becomes useful when you connect concept, implementation, and real-user outcome together.

Study flow for better retention

  1. Read one section, run one tiny example, then explain the idea in your own words.
  2. Use a simple cycle: understand, implement, test, and explain.
  3. If you can teach it in 45 seconds without notes, you understood it.

Common Mistakes To Avoid

  • Moving forward without checking whether the current concept is truly clear.
  • Copying code exactly without experimenting with small changes.
  • Skipping edge cases and only testing happy-path behavior.
  • Assuming one pattern works for every scenario without trade-off analysis.

Practice Sprint (15-25 Minutes)

  • Before running sample code, predict output and behavior in one sentence.
  • Build one tiny example from memory after finishing this lesson.
  • Write one paragraph about where this concept fits in a real app.
  • Create one failure scenario and verify your app handles it safely.
  • Complete the required exercises without using hints on the first attempt.
  • Answer this question out loud before checking quiz options: "How do you make text bold?".

Quick Glossary

  • widget: A reusable UI building block in Flutter.
  • build: The method that describes UI for the current state.

Code Comprehension Drill

  • State the purpose of the code block in one line before reading details.
  • Mark inputs, state changes, and final output.
  • Change one small value and predict what should happen before running.
  • Run again and compare your prediction with actual behavior.

Lesson Completion Checklist

  • I can explain "Text & Styling" in simple words without reading notes.
  • I can describe one real app situation where this concept is required.
  • I know at least one mistake to avoid: Moving forward without checking whether the current concept is truly clear.
  • I can modify one code sample and correctly predict the behavior change.
  • I can finish required exercises with understanding, not trial-and-error guesses.

Frequently Asked Questions

How do you make text bold?

Use fontWeight property in TextStyle to control text thickness.

What does TextOverflow.ellipsis do?

ellipsis truncates text and shows ... at the end.

Which widget displays text with mixed styles?

RichText with TextSpan allows different styles in one text block.

What does maxLines: 2 do on a Text widget?

maxLines restricts the text to a maximum number of lines, useful with overflow.

Suggest Improvement

Something seems incorrect, unclear, or missing? Let us know.

About The Author

FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.

Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.

Sign in to continue with exercises and quiz for this lesson.

Sign In to Continue