How to align widgets in different position of the screen in Flutter?

Posted by Andre Scott | Updated on

In this example, I will share how to align one widget to the top of the screen and center another widget to the middle of the screen in Flutter.

One option is to use an Expanded widget. This widget will expand fill all the space available in the parent, and then you center the child inside it. Note that this only works inside Flex widgets, like Row, Column etc.

In your case, I also recommend removing the screenWidth variable for the row width, and use the Expanded widget to make the container fill the screen horizontally.

This is the final code:


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers