Ternary Conditional operator

on Saturday, 18th of July, 2020

The ternary operator is technically that: an operator. But, it's also kind of an if/else substitute. It's also kind of a ?? alternative, depending on the situation. The ternary expression is used to conditionally assign a value. It's called ternary because it has three portions: the condition, the value if the condition is true, and the value if the condition is false.

String alert = isReturningCustomer ? 'Welcome back to our site!' : 'Welcome, please sign up.';

In the above example isReturningCustomer is a boolean. If it is true, the variable called alert will be assigned the value "Welcome back to our site!". Otherwise, alert will be assigned the value "Welcome, please sign up.".

Join thousands of Flutter developers.

Sign up for infrequent updates about Flutter and Dart.

You can get all this content and more in one place. Check out my new book Flutter in Action