Home > Mobile >  Can someone explain what does the colon do in this case? and the overall definition of this code/
Can someone explain what does the colon do in this case? and the overall definition of this code/

Time:06-21

Hi I'm learning Flutter and I came across this line of code which looks like this.

width: _width < 1000 ? _width / 1.2 : 833,
height: _width < 1000 ? _width / 2 : 500,

Can someone please explain what does the colon mean in this case? Or just the overall meaning is fine.

CodePudding user response:

It's a ternary operator, basically shorthand for if-then-else

i.e. "if _width is less than 1,000 return width divided by 1.2 else return 833"

  • Related