Center Widget – Flutter Widget Guide By Flutter Agency

· 3 min read
Center Widget - Flutter Widget Guide By Flutter Agency
Center Widget - Flutter Widget Guide By Flutter Agency

Welcome back to our Flutter widget guide by FlutterAgency series. In the previous article, we have gone through the Container widget so this time we will get into the Center Widget.

What is Center Widget?

Center Widget is a widget that centers its child within itself or in other words we can say that it will wrap any widget to center to its parent widget.

The constructor of Center Widget will look like below :

Center({
   Key key,
   double widthFactor,
   double heightFactor,
   Widget child,
 });
  • widthFactor: It accepts a double value. It will automatically set its width to the child’s width multiplied by this factor. widthFactor Can be both greater and less than 1.0 but must be positive.
  • heightFactor: heightFactor will also accept double values. It will automatically set it’s height to height to the child’s height multiplied by this factor. heightFactor can be both greater and less than 1.0 but must be positive.
  • child: child property will specify widget below the current widget in the tree. child widget can only have only one child. To use multiple children, use widgets such as Row, Column, or Stack, which have children’s property, and then provide the children to that widget.

The code snippet will look like below :

Center(
      child: 
      // widget
      )

An example for it will look like below :

Center(
    child: Container(
    height: 100,
    width: 100,
    color: Colors.orangeAccent,
    ),
    );

We will get output like below :

Center Widget - Flutter Widget Guide By Flutter Agency

Center Widget

Thanks for reading !!!

Do let us know if you need further assistance with Flutter?

FlutterAgency.com is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

FlutterAgency.com is one of the most popular online portal dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge on Flutter.

Leave a Reply