Difference Between Rows and Columns vs Container in Flutter
In this article, we’ll learn about the key differences between Container and Row/Column widgets. Row and Column both widgets belong to a similar category and have identical uses. These are the basic widgets that you would use in almost every flutter app. We will discuss them in brief.
This is the most used widget in every flutter app. It is mostly used to style its child widgets. It takes only one child. Some flutter widgets, focus only on their core functionality and does not contain much styling options. The container widget comes to the rescue and provides you with various common painting, positioning, and sizing widgets.
Container( child: Widget //Another flutter widget )
These are widgets that can contain multiple child widgets. The row is the widget that can display various child widgets in a horizontal manner. The column displays child widgets in a vertical manner. By default, these widgets don’t support scrolling. It can be enabled by wrapping with other widgets. But, if there are numerous child widgets, it is preferred to use ListView.
Row( children: [ Container(), // First Widget Text(), // Second Widget ----, ----, // Multiple Widgets ]) Column( children: [ Container(), // First Widget Text(), // Second Widget ----, ----, // Multiple Widgets ])
|Takes exactly one child widget||Takes multiple (unlimited) child widgets|
|Rich alignment and styling options available||Alignment options available, but there are no styling options|
|Flexible width (e.g. child width, available width, …)||Always takes full available height (column) /width (row)|
|Perfect for custom styling and alignment||Must-use if widgets sit next to/above each other|
In the above example, we have shown how row and column widgets are used in combination with a container widget. When no styling options were available in the child widget, we wrapped it with a container to add some padding to the child widget.