What is Text Widget?

What is Text Widget?

ยท

1 min read

In Flutter, the Text widget is a fundamental component used to display text within your application. It allows you to present a wide range of textual content, from simple labels to more complex paragraphs. The Text widget is highly customizable, enabling you to control various aspects of the displayed text, such as style, size, color, and more.

Here's a basic example of using the Text widget in Flutter:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Flutter Text Widget Example'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                'Hello, Flutter!',
                style: TextStyle(
                  fontSize: 24,
                  fontWeight: FontWeight.bold,
                  color: Colors.blue,
                  fontStyle: FontStyle.italic,
                ),
                overflow: TextOverflow.ellipsis,
                maxLines: 2,
              ),
            ],
          ),
        ),
      ),
    );
  }
}

In this example:

  • The text is styled with a larger font size, bold, blue color, and italicized.

  • Overflow is handled with ellipsis, and the maximum number of lines is set to 2.

ย