Skip to main content
The ?. operator, formally known as the null-aware access operator or conditional member access operator, provides a safe mechanism to access properties or invoke methods on an expression that may evaluate to null. It evaluates the left-hand operand; if the operand is null, the operation short-circuits and yields null without throwing a NoSuchMethodError. If the operand is non-null, it proceeds with standard member access or invocation. Syntax
Evaluation Mechanics
  1. The runtime evaluates expression.
  2. If expression == null, the entire expression expression?.member immediately evaluates to null. If member is a property of type T or a method returning type T, the static type of the resulting expression is T?. Exception: If member is a method that returns void, the static type of the expression remains void, not void?.
  3. If expression != null, the runtime accesses or invokes member on the resolved object.
Code Visualization Property Access:
Method Invocation:
Short-Circuit Chaining When multiple ?. operators are chained, the evaluation halts at the exact point the first null is encountered. Subsequent property accesses or method invocations in the chain are completely bypassed.
Interaction with Standard Access (.) Dart employs “null-aware shorting.” If a null-aware operator short-circuits an expression chain, any subsequent standard dot operators (.) within that continuous chain are also bypassed at runtime. However, the expression must still satisfy Dart’s static compile-time null safety checks. The ?. operator only handles the potential nullability of the operand immediately preceding it. Subsequent standard accesses (.) are only permitted by the compiler if the preceding properties are statically known to be non-nullable.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More