?. 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
- The runtime evaluates
expression. - If
expression == null, the entire expressionexpression?.memberimmediately evaluates tonull. Ifmemberis a property of typeTor a method returning typeT, the static type of the resulting expression isT?. Exception: Ifmemberis a method that returnsvoid, the static type of the expression remainsvoid, notvoid?. - If
expression != null, the runtime accesses or invokesmemberon the resolved object.
?. 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.
.)
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





