Home > OS >  How to create a widget that takes no space in MainAxisAlignment.spaceBetween?
How to create a widget that takes no space in MainAxisAlignment.spaceBetween?

Time:12-19

If you have a Row in Flutter and set it to mainAxisAlignment: MainAxisAlignment.spaceBetween, all Children gets evenly spaced by the distances between each other.

However, if you are conditionally displaying Widgets in this Row ((boolean) ? Display : Container()), the empty Container actually counts as a Widget that takes space with this particular mainAxisAlignment, and you will see empty space instead of Flutter just ignoring it completely and realigning as if it does not exist.

How do I keep using MainAxisAlignment.spaceBetween and use a conditional empty Widget at the same time?

CodePudding user response:

You shouldn't use

(boolean) ? Display : Container()

but simply

if (boolean) Display
  • Related