Search code examples
flutterdartflutter-layoutflutter-web

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


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.


Solution

  • 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"