flutter
  1. flutter-text

Flutter Text

The Text widget in Flutter is used to display a string of text on the screen. It is one of the most commonly used widgets in Flutter.

Syntax

Text(
  'Your text here',
  style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20)
)

Example

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Text Example',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Flutter Text Example')),
      body: Center(
        child: Text(
          'Hello, World!',
          style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20)
        ),
      ),
    );
  }
}

Output

Flutter Text Output

Explanation

The Text widget takes in a string of text and displays it on the screen. It also has an optional parameter called style which is used to customize the appearance of the text.

In the example above, the text 'Hello, World!' is displayed on the screen with a bold font weight and font size of 20.

Use

The Text widget can be used to display any string of text on the screen. It is commonly used for headings, labels, and other text-based elements in a Flutter app.

Important Points

  • The Text widget is used to display text on the screen in a Flutter app.
  • The style parameter can be used to customize the appearance of the text.
  • The Text widget can be used for headings, labels, and other text-based elements in a Flutter app.

Summary

The Text widget is a commonly used widget in Flutter for displaying text on the screen. It takes in a string of text and can be customized using the style parameter. It is used for headings, labels, and other text-based elements in a Flutter app.

Published on: