What is the difference between a Stack and a Column in Flutter?

Viewed 3055

I'd like to know what are the differences between a Stack and a Column in Flutter? I know that both widgets are responsiple for stacking Widgets on top of each other I'm a bit confused when to use a Stack and when to use a Column?

I also know that a ListView is scrollable either horizontally or vertically and therefore distinguishes from a Column and a Stack. But neither the Stack nor the Column is scrollable.

So what is the difference between these two?

3 Answers

Stack widget positions its children relative to the edges of its box. It doesn't necesserily put them on top of each other but it is possible. Positioned widget is very useful to position the children in a Stack.

Column widget displays its children in a vertical array. It splits the available area to multiple areas. Expanded widget is a good option to adjust the space ratio between children.

Row widget is just a horizontal variant of Column.

In a single line difference.

1.Stack can Overlap widgets but columns can't overlap widgets.

if you are coming from an android background then this should be easy to understand like this.

  • the stack is the relative layout and the column is LinearLayout but in the Horizontal orientation.
Related