Flutter Spacer vs Expanded

What is the difference between Expanded and Spacer in Flutter? Why Flutter team added Spacer when we already have Expanded ?

Both Spacer and Expanded does the same job that is they fill up the remaining space in a widget like Row or Column . Before Spacer , we had to use

Expanded(child: Container())

And which is not very good. With Spacer we only have to use

Spacer()

So, using Spacer , we prevent us from writing more code and it also gives clear indication that we are just using it to fill up the remaining space. Both of them have same property of flex which defaults to 1 . The only difference is we don’t have child property which makes sense. In fact Spacer is

Expanded(child: SizedBox.shrink());

TL;DR

Spacer() 

is equivalent to

Expanded(child: Container())
1 Like