Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The . (dot) operator is the standard member access operator in Dart. It is used to extract properties (fields, getters, setters), invoke methods, perform method tear-offs, and access members bound to an object instance, a class namespace, an imported library prefix, or an extension.

Syntax

expression.memberIdentifier

Technical Mechanics

  • Left-Hand Side (LHS): An expression that evaluates to an object instance, a class type (for static access), or a library prefix.
  • Right-Hand Side (RHS): The exact identifier of the member being accessed.
  • Compile-time Resolution: In statically typed Dart, the analyzer resolves the RHS identifier at compile time against the static type of the LHS interface, class namespace, library namespace, or applicable extension in the current lexical scope.
  • Runtime Evaluation: The operator evaluates strictly left-to-right. The LHS is evaluated first. Once evaluated, the member is accessed, extracted, or dispatched on the resulting object in memory.

Syntax Visualization

Instance Member Access: Accessing fields or methods bound to a specific object instance.
// Property read/write
instance.propertyName;
instance.propertyName = value;

// Method invocation
instance.methodName(arguments);
Method Tear-offs: Extracting a method as a closure object without invoking it.
var closure = instance.methodName;
Static Member Access: Accessing class-level fields or methods bound to the class namespace itself.
ClassName.staticProperty;
ClassName.staticMethod(arguments);
Library Prefix Access: Accessing top-level members of an imported library namespace.
import 'dart:math' as math;

math.pi;
math.max(1, 2);
Extension Member Access: Invoking extension methods or properties, which are resolved statically based on the LHS type.
instance.extensionMethod();
Chaining: Because the . operator returns the result of the RHS evaluation, it inherently supports chaining. The evaluated result of the first access becomes the LHS for the subsequent . operator.
expression.memberA.memberB.methodC()

Nullability and Type Safety

In Dart’s sound null safety system, the . operator interacts with nullable types under specific resolution rules:
  • Permitted Nullable Access: The . operator can be safely used on a nullable LHS expression to access members inherited from Object? (specifically toString(), hashCode, and runtimeType). It is also used to invoke extension members explicitly defined on a nullable type (e.g., extension on String?).
  • Compile-time Restrictions: Attempting to access any other instance member on a statically-typed nullable type (e.g., T?) using the . operator results in a compilation error. The analyzer enforces the use of the null-aware access operator (?.) or explicit null-checks. The dynamic type is an exception; while it permits null values, it bypasses static type checking and allows . access at compile time.
  • Runtime Behavior: If the LHS expression evaluates to null at runtime (which can occur via dynamic dispatch or unsafe type casting) and the RHS does not resolve to an Object? member or an applicable nullable extension, the . operator unconditionally throws a NoSuchMethodError.
Master Dart with Deep Grasping Methodology!Learn More