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 in Dart that subtracts exactly 1 from its numeric operand. It mutates the underlying variable in place and requires the operand to be a non-final, non-const variable.
The operator functions in two distinct evaluation contexts based on its placement relative to the operand: prefix and postfix.
Prefix Decrement (--var)
In the prefix position, the operator performs a pre-decrement. Dart subtracts 1 from the operand before evaluating the expression. The expression resolves to the newly decremented value.
Postfix Decrement (var--)
In the postfix position, the operator performs a post-decrement. Dart evaluates the expression using the current value of the operand, and subtracts 1 from the operand after the evaluation is complete.
Technical Constraints and Behavior
- Type Requirements: The operand must be of type
num(intordouble), or a custom class that implements the-operator. - Immutability: Applying
--to afinalorconstvariable results in a compile-time error, as the operator fundamentally requires reassignment. - Desugaring: Dart does not allow direct overriding of the
--operator. Instead, the Dart compiler treatsa--or--aas syntactic sugar fora = a - 1. - Custom Classes: Because of the desugaring mechanism, if you want to use the
--operator on an instance of a custom class, you must override the binary-operator. The class must also be assigned to a mutable variable (varor explicit type, notfinal).
Master Dart with Deep Grasping Methodology!Learn More





