Skip to main content
The conditional member access operator (?.) accesses a property or invokes a method on a receiver only if that receiver is non-null. If the receiver is null, the expression short-circuits and evaluates to null immediately, bypassing the member access.

Syntax

receiver?.member

Operational Semantics

The evaluation of the expression a?.b proceeds as follows:
  1. Evaluation of Operand: The left-hand operand (a) is evaluated.
  2. Null Check:
    • If a is null, the evaluation stops (short-circuits). The value of the entire expression is null.
    • If a is not null, the member access (.b) is executed on the object.
  3. Result: The expression returns either the value of b or null.

Type Implications

The return type of a conditional access expression is always the nullable version of the accessed member’s type. If a member b has a return type of T, the expression a?.b has a static type of T?. This applies even if T is already nullable; the resulting type remains T? (nullable types are idempotent).
class Container {
  int id = 100;
}

Container? box;

// Although 'id' is defined as int, the expression 'box?.id' resolves to int?.
// The variable 'result' is inferred as int?.
var result = box?.id; 

Chaining

The operator can be chained to safely traverse deep object structures. If any link in the chain evaluates to null, the remainder of the chain is skipped, and the entire expression evaluates to null.
// If a is null, b and c are not accessed.
// If a.b is null, c is not accessed.
var result = a?.b?.c;
Master Dart with Deep Grasping Methodology!Learn More