Operators
Operators are special symbols that perform operations on operands. Dart supports a rich set of operators for various operations.
Arithmetic Operators
Increment and Decrement
Equality and Relational Operators
Logical Operators
Assignment Operators
Type Test Operators
Bitwise Operators
Conditional Expressions
Ternary Operator
Null-coalescing Operator
Cascade Notation
Allows you to perform a sequence of operations on the same object:
Spread Operator
Null-aware Operators
Null-aware Access
Null-aware Assignment
Null Assertion
Index Operator
Operator Precedence
From highest to lowest:
- Postfix:
expr++,expr--,(),[],.,?. - Unary prefix:
-expr,!expr,~expr,++expr,--expr - Multiplicative:
*,/,%,~/ - Additive:
+,- - Shift:
<<,>> - Bitwise AND:
& - Bitwise XOR:
^ - Bitwise OR:
| - Relational:
>=,>,<=,<,as,is,is! - Equality:
==,!= - Logical AND:
&& - Logical OR:
|| - Null-aware:
?? - Conditional:
expr1 ? expr2 : expr3 - Cascade:
..,?.. - Assignment:
=,*=,/=,+=,-=, etc.
Operator Overloading
You can override operators in custom classes:
Best Practices
- Use parentheses to make complex expressions clearer
- Prefer
??over explicit null checks when providing defaults - Use cascade notation for multiple operations on the same object
- Be careful with
!- only use when you're certain the value isn't null - Use
?.for safe navigation through potentially null objects