I have a space where I to show either widget1 or widget2 (and never both). How?
In fact, widget1 to contain a simple case of retrieved information and a button to switch to show widget2 (with more information) instead.
The only solution that I came up is to use Column(children: [widget1, widget2])
and tweak visibility of both widgets, but that’s ugly. For example, there is no indication what is better Column
or Row
.
2
Answers
To simply solve that, you can use a ternary operator with a widget like a container (or any that has a single child):
To do this, you have multiple options:
(1) You can use conditional
spread operator
inside a column/widget(2) You can use
ternary operator
inside a column/widget(3) You can use
Visibility
widget inside a column/widgetternary operator
if you haveonly one condition or non-nested conditions
spread operator
if you havemultiple conditions or nested conditions
Visibility
widget (burnot recommended
)