As many of you know, Flutter has taken the cross-platform application development by a storm since its launch, and is one of the fastest accepted and growing technologies right now—everybody is talking about it in tech world!
So, you came to know about Flutter from your friend, colleague, some articles or some other way, and you decided to give it a shot. One of the first thing most of the Flutter developers might have learned is “Everything is a Widget.” Anything and everything you see on the screen is a widget.
And one of the most basic widget types is Layout widgets. Layout widgets are divided in 2 parts:
The names do the most of the explaining about these categories. So, without further ado, let’s start with single child layout widgets.
Align is a widget that aligns its child within itself and optionally sizes itself based on the child’s size. Align widget will wrap itself around the widget you desire to set on a fix location on the screen. Options that align widget give are shown below.
Properties
There are 3 different ways you can use alignment property:
alignment: Alignment (0.1, 0.8)
Most of the time we will be using default option given by the flutter to adjust our child widget on the screen.
Here are few examples on how to use default alignment option provided by flutter:
Center widget will starch itself to take as much space as possible and it will render its child widget in the center of itself. It is safe to say that Center is the mostly same as Align but with only one alignment that is center.
Properties
Here is how Center will render its child Widget:
It is not possible to give height or width to center widget. It will always take all available space.
A Container can be used to store it child widget on the rendering tree, and then it can be position around the screen according to the requirement. In contras to Center widget it is possible to give the container height and width, but it is not possible to set its position on rendering screen like Align widget. But you can still set alignment for the child, which will determine where child would b placed inside the container.
Basically, a container is like a box that will store the contain but its size can be modified.
Properties
Sizedbox is basically the same as container but with a lot of limitation. Those limitation include, it is not possible to give margin, padding, color or decoration to sizedbox.
Sized box will automatically take size of its child, but if it is with no child and height and width null height and width will be taken as 0.
Most of the widget inn flutter takes size of its parents if not given and they cannot surpass it. A widget that is a specific size but passes its original constraints through to its child, which may then overflow.
Properties
Padding works same as padding in container. In fact, container uses Padding widget when padding property is used inside the container. So, if the only need is to add padding around the child Padding will do it much quicker in compare to using container and then use padding property.
Let’s talk!
We’d love to hear what you are working on. Drop us a note here and we’ll get back to you within 24 hours
Let’s talk!
We’d love to hear what you are working on. Drop us a note here andwe’ll get back to you within 24 hours
In this episode of the The Lazy CEO Podcast,…
Join us for an enlightening episode of The CEO…
Creating multi-agent workflows is the future of AI development,…
How has sunflower lab's focus on integrating ai, data…
Businesses are quickly shifting towards optimized processes. And the…
Developers often make mistakes when using Power Automate, which…