Reputation: 4450
The padding
property of Padding
widget is also available in Container
widget. Then what is the point of using Padding
widget instead of Container
widget? I found that Padding
has const
constructor which Container
doesn't have. Is this the only reason of using Padding
instead of Container
?
Upvotes: 0
Views: 149
Reputation: 310
There isn't really any difference between the two. If you supply a Container.padding
argument, Container
simply builds a Padding
widget for you.
Container doesn't implement its properties directly. Instead, Container combines a number of simpler widgets together into a convenient package. For example, the Container.padding property causes the container to build a Padding widget and the Container.decoration property causes the container to build a DecoratedBox widget. If you find Container convenient, feel free to use it. If not, feel free to build these simpler widgets in whatever combination meets your needs.
In fact, the majority of widgets in Flutter are simply combinations of other simpler widgets. Composition, rather than inheritance, is the primary mechanism for building up widgets.
Upvotes: 1