What is Text Widget in Flutter: Simple Explanation and Example
Text widget in Flutter is used to display a string of text on the screen. It is a basic building block for showing readable content in your app's user interface.How It Works
The Text widget in Flutter works like a label or sign in real life that shows words or sentences. When you add a Text widget to your app, Flutter draws the text on the screen where you place it.
Think of it as putting a sticky note on a wall to show a message. You can change the size, color, and style of the text to make it look just right. Flutter handles all the details of drawing the letters clearly and nicely on different screen sizes.
Example
This example shows how to use the Text widget to display a simple greeting message in the center of the screen.
import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return const MaterialApp( home: Scaffold( body: Center( child: Text('Hello, Flutter!'), ), ), ); } }
When to Use
Use the Text widget whenever you want to show words or sentences in your app. It is perfect for titles, labels, instructions, or any readable content.
For example, you might use Text to show a welcome message on the home screen, display a button label, or show error messages to users. It is one of the most common widgets because almost every app needs to show text.
Key Points
- Text widget displays a string of text on the screen.
- You can customize font size, color, weight, and style.
- It is used for any readable content in the app UI.
- Works well inside layout widgets like
Center,Row, andColumn.