Center Widget Horizontally In Flutter

In this article, you will learn How To Center A Widget Horizontally. Creating Widgets Here, you have a Scaffold with Row widget which you will…

The post Center Widget Horizontally In Flutter appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Jatin Hemnani

In this article, you will learn How To Center A Widget Horizontally.

Creating Widgets

Scaffold(
      backgroundColor: Color(0xffff6b81),
      appBar: AppBar(
        title: Text(
          'Home',
        ),
        centerTitle: true,
      ),
      body: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Container(
            width: 150,
            height: 150,
            color: Colors.purple,
          )
        ],
      ),
    );

Here, you have a Scaffold with Row widget which you will use to center a widget. There is a property i.e mainAxisAlignment and this property takes the MainAxisAlignment function.

mainAxisAlignment: MainAxisAlignment.center,

To center a widget you can use MainAxisAlignment.center method. And in this way, you can center any widget.

Result

The post Center Widget Horizontally In Flutter appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Jatin Hemnani


Print Share Comment Cite Upload Translate Updates
APA

Jatin Hemnani | Sciencx (2021-03-05T16:58:57+00:00) Center Widget Horizontally In Flutter. Retrieved from https://www.scien.cx/2021/03/05/center-widget-horizontally-in-flutter/

MLA
" » Center Widget Horizontally In Flutter." Jatin Hemnani | Sciencx - Friday March 5, 2021, https://www.scien.cx/2021/03/05/center-widget-horizontally-in-flutter/
HARVARD
Jatin Hemnani | Sciencx Friday March 5, 2021 » Center Widget Horizontally In Flutter., viewed ,<https://www.scien.cx/2021/03/05/center-widget-horizontally-in-flutter/>
VANCOUVER
Jatin Hemnani | Sciencx - » Center Widget Horizontally In Flutter. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/05/center-widget-horizontally-in-flutter/
CHICAGO
" » Center Widget Horizontally In Flutter." Jatin Hemnani | Sciencx - Accessed . https://www.scien.cx/2021/03/05/center-widget-horizontally-in-flutter/
IEEE
" » Center Widget Horizontally In Flutter." Jatin Hemnani | Sciencx [Online]. Available: https://www.scien.cx/2021/03/05/center-widget-horizontally-in-flutter/. [Accessed: ]
rf:citation
» Center Widget Horizontally In Flutter | Jatin Hemnani | Sciencx | https://www.scien.cx/2021/03/05/center-widget-horizontally-in-flutter/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.