TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
-- operator is a unary arithmetic decrement operator that evaluates its operand minus 1, yields a new object representing that value, and updates the operand’s reference to point to this new object. Because numbers in Dart are immutable, this operator does not mutate the existing value in memory; instead, it performs a reassignment. It requires a mutable variable (non-final and non-const) and functions in two distinct evaluation modes based on its syntactic position: prefix and postfix.
Prefix Decrement (--var)
When the operator precedes the operand, Dart executes a pre-decrement operation. At runtime, the expression evaluates the operand minus 1, updates the variable’s reference to the newly created object, and then yields this new value as the result of the expression.
var--)
When the operator follows the operand, Dart executes a post-decrement operation. At runtime, the expression caches the variable’s current object reference to yield as the final result, evaluates the operand minus 1 to create a new object, and updates the variable’s reference to this new object.
var = var - 1, the -- operator provides a strict single-evaluation guarantee. For complex assignable expressions (l-values) like list[getIndex()]-- or getObj().prop--, Dart evaluates the receiver and any index expressions exactly once at runtime. A literal var = var - 1 expansion would incorrectly evaluate those components twice.
To use the -- operator, the following conditions must be met:
- The operand must be an assignable expression (a mutable l-value).
- The operand’s type must implement the subtraction operator (
operator -) accepting anintas the right-hand operand. - The return type of that
operator -must be assignable back to the original variable’s static type to satisfy the implicit assignment step.
int and double types, the -- operator functions on custom class instances provided the class explicitly overrides operator - and adheres to the type assignability requirement.
Master Dart with Deep Grasping Methodology!Learn More





