How do you make text bold?
Use fontWeight property in TextStyle to control text thickness.
Display and style text in Flutter
Passing the Quiz & Exercises is mandatory to earn FX and proceed. If you fail, try again to gain the required FX, then the Proceed button will become available.
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
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
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.
1// --- Simple Text ---2Text('Hello World')345// --- Styled Text ---6Text(7'Styled Text',8style: TextStyle(9fontSize: 24, // Text size10fontWeight: FontWeight.bold, // Bold text11color: Colors.blue, // Text color12letterSpacing: 2, // Space between letters13decoration: TextDecoration.underline, // Add underline14),15)161718// --- Handling Long Text ---19Text(20'This is a very long text that might overflow',21maxLines: 2, // Max 2 lines22overflow: TextOverflow.ellipsis, // Show ... if too long23textAlign: TextAlign.center, // Center the text24)
| Property | Example | Purpose |
|---|---|---|
fontSize | 24 | Text size |
fontWeight | FontWeight.bold | Thickness |
color | Colors.red | Text color |
fontFamily | 'Roboto' | Custom font |
letterSpacing | 2.0 | Space between letters |
height | 1.5 | Line height |
When you need different colors, sizes, or weights within a single line of text, use the RichText widget or the Text.rich shorthand.
1// --- RichText: Multiple Styles in One Text ---2// Use when you need different colors/styles in same line34RichText(5text: TextSpan(6// Default style for all text7style: TextStyle(color: Colors.black),89// Children with different styles10children: [11TextSpan(text: 'Hello '), // Normal12TextSpan(13text: 'Flutter', // Bold & Blue14style: TextStyle(15fontWeight: FontWeight.bold,16color: Colors.blue,17),18),19TextSpan(text: '!'), // Normal20],21),22)232425// --- Shorter way with Text.rich ---26Text.rich(27TextSpan(28children: [29TextSpan(text: 'Price: '), // Normal text30TextSpan(31text: '$99', // Bold price32style: TextStyle(fontWeight: FontWeight.bold),33),34],35),36)
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.
Good UI typography is not random styling. Build a clear hierarchy:
When hierarchy is consistent, users scan faster and understand content structure without effort.
Display and style text in Flutter. This lesson adds one more building block for creating stable and user-friendly Flutter apps.
Build confidence with basics first; speed comes later.
After reading, rewrite the concept in your own words and apply it in a tiny runnable sample.
Each lesson becomes useful when you connect concept, implementation, and real-user outcome together.
Use fontWeight property in TextStyle to control text thickness.
ellipsis truncates text and shows ... at the end.
RichText with TextSpan allows different styles in one text block.
maxLines restricts the text to a maximum number of lines, useful with overflow.
Something seems incorrect, unclear, or missing? Let us know.
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