Is it possible to have an inline if with more than one expression per condition?

Issue

Is it possible to have multiple expression in an inline if or do I necessarily need to use the traditional if statement this purpose?

widget.queueList[j] == 0 ? (jumpAround(); j++;) : widget.queueList[j]--;

The above is my code, is there a way for me to call jumpAround() and increment j in the same expression?

Solution

Yes, you can do it like this:

void main() {
  int c = 0;

  c == 0 ? {print('c: $c'), c++, print('c: $c')} : {print('c: $c')};
}

Answered By – Basel Abuhadrous

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.