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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.