Center Widget

What is Center Widget?

The Center widget is to create a widget that centers its child.

Default Constructor

The default constructor creates a widget that centers its child.

Center(
      child: //
    ),

Constructor Parameters

It contains many input parameters which can be configured to change its behavior and appearance.

The child parameter is to add the widget below Center widget in the tree.

Code snippet

This code snippet shows how to configure Center widget with different parameters.

Center(
      child: Text(
        'Hello World!',
        textDirection: TextDirection.ltr,
      ),
    ),

Demo Code

This example shows how to center a text.

import 'package:flutter/material.dart';

void main() {
  runApp(
    Center(
      child: Text(
        'Hello World!',
        textDirection: TextDirection.ltr,
      ),
    ),
  );
}