Dart Flutter : How to use multiple widget in ternary operator inside a flutter widget

Issue

I wanna use multiple widget in ternary operator like this.
But it’s error.Can I do?

Container(
  child: (if value != null)
  ? Widget1(...),Widget2(...)
    : const SizedBox.shrink(),
)

Solution

Try wrapping each of those Widgets inside a Column() (or into an other widget you find appropriate for your app as Row).

Container(
  child: value != null
  ? Column(children:
                [Widget1(...),
                 Widget2(...)]
            )
    : const SizedBox.shrink(),
)

Answered By – Dani3le_

Answer Checked By – Marilyn (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.