I am curious about this. I have seen many example using Container()
for dummy hidden widget, for example, when loading has completed, then we setState(() { _isLoaded = true; });
.
So we can use the state like this, right?
return _isLoaded ? Container() : LoaderWidget();
Or maybe using SizedBox()
is actually better because it don't take much parameters and often used for padding anyway?
return _isLoaded ? SizedBox() : LoaderWidget();
Or am I wrong?
Difference Between SizedBox and Container Widgets Container can also be used to add space between widgets Or wrap the child and give it a specific height. But Container has some extra properties. So, We can use SizedBox instead where we can specify child , height and width .
Placeholder Widgets. Use SizedBox instead of Container as Placeholder widgets.
To start from a Blank Page, select + Create New under the Blank Page template. The UI Builder will then open and show a blank page.
In case of use as a placeholder:
Container if the widget has no child, no height, no width, no constraints, and no alignment, but the parent provides bounded constraints, then Container expands to fit the constraints provided by the parent.
SizedBox if the widget has no child, no height, no width, then width and height are zero.
Therefore, SizedBox()
serves more as a syntactic placeholder.
Also, note that SizedBox() is a const
constructor but Container() is not. The first one allows the compiler to create more efficient code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With