I want to return two widgest when one if
is true. Something like this:
Row(
children: [
...
if (session.server.autoVenta)
SizedBox(
width: size.width * 0.16,
child: const TextPrimary(
text: "N° Doc:",
),
),
if (session.server.autoVenta)
SizedBox(
width: size.width * 0.24,
child: Text(order.documento),
),
]
)
But using only one if
.
I've searched on google but I couldn't find anything.
CodePudding user response:
Like
Row(
children: [
if (true) ...[
Widget(),
Widget(),
],
Widget(),
],
)
CodePudding user response:
you can many options to do it :
first, you can use the spread operator inside the children
in your column to add a List
of widgets at once :
Row(
children: [
/* other widgets */
if (condition) ...[
YourWidget1(),
YourWidget2(),
YourWidget3(),
],
you can use for it also a separate List<Widget>
containing your widgets
or you can use nested Row
if you don't want the spread operator :
Row(
children: [
/* other widgets */
if (condition) RowWidgets(),
),
Widget RowWidgets() {
return Row(
children: [
YourWidget1(),
YourWidget2(),
YourWidget3(),
],
);}