?..) is a syntactic sugar that allows a sequence of operations to be performed on a target object only if that object is not null. It combines the functionality of the standard cascade operator (..) with short-circuiting null safety checks.
Syntax
Operational Semantics
The?.. operator functions according to the following execution flow:
- Receiver Evaluation: The expression to the left of the operator (the receiver) is evaluated once.
- Null Check:
- If the receiver evaluates to
null, the entire cascade expression short-circuits and immediately returnsnull. No subsequent methods or property setters in the chain are executed. - If the receiver evaluates to a non-null object, the operations defined in the cascade are executed sequentially.
- If the receiver evaluates to
- Return Value: Unlike the dot operator (
.) or the null-aware dot operator (?.), which return the result of the member access, the null-aware cascade operator returns the receiver (the original object) ornull.
Code Visualization
The following example demonstrates the mechanical difference between a standard cascade and a null-aware cascade when handling nullable types.Chaining Behavior
When starting a cascade chain with?.., subsequent operations in the same chain typically use the standard cascade operator (..). The initial null check provided by ?.. guards the entire chain; if the receiver is null, the subsequent .. operations are skipped entirely.
Master Dart with Deep Grasping Methodology!Learn More





