flutter
/

Flutter Center Widget Tutorial for Beginners

Last Sync: Today

On this page

5
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

flutter

Flutter Center Widget Tutorial for Beginners

What is Center in Flutter?

Center is a widget that centers its child within itself. It's actually a specialized version of Align with alignment: Alignment.center. It's one of the simplest and most commonly used layout widgets.

Basic Usage

DARTRead-only
1
Center(
  child: Text('I am centered'),
)

The Center widget will expand to fill its parent (if the parent allows it) and then place the child in the center.

Center vs Align

Center is equivalent to Align(alignment: Alignment.center). Use Center for simplicity when you just need centering. Use Align when you need more precise positioning (e.g., top‑right).

When Does Center Not Work?

Center will only work if its parent provides enough constraints. For example, if Center is placed inside a Container with no fixed size, and that Container is inside a Column, Center might not have a bounded size to center within. In such cases, wrap the Center with a SizedBox or Expanded.

Key Points to Remember

  • Center centers its child both horizontally and vertically.
  • It expands to fill its parent (if possible).
  • It's a convenient shorthand for Align(alignment: Alignment.center).

Try it yourself

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('Center Example')),
        body: Center(
          child: Container(
            width: 150,
            height: 150,
            color: Colors.blue,
            child: Center(child: Text('Inner')),
          ),
        ),
      ),
    );
  }
}

Test Your Knowledge

Q1
of 1

What does the Center widget do?

A
Centers its child horizontally only
B
Centers its child both horizontally and vertically
C
Centers itself within its parent
D
Expands to fill its parent without centering

Previous

flutter align widget

Next

flutter wrap widget

Related Content

Need help?

Explore our comprehensive docs or start a chat with our tech experts.