Conditional Expression and Control Flow
Conditional expressions
Dart has two operators that let you concisely evaluate expressions that might otherwise require if-else statements:1.condition ? expr1 : expr2
- If condition is true, evaluates expr1 (and returns its value); otherwise, evaluates and returns the value of expr2.
2.expr1 ?? expr2
- If expr1 is non-null, returns its value; otherwise, evaluates and returns the value of expr2.
When you need to assign a value based on a boolean expression, consider using
?:
.
Comments
Post a Comment