1

I want to return two widgets when one condition 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.

2 Answers 2

5

Like

Row(
  children: [
    if (true) ...[
      Widget(),
      Widget(),
    ],
    Widget(),
  ],
)
Sign up to request clarification or add additional context in comments.

Comments

1

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(),
     ],
);}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.