Skip to main content
The = operator in Dart is the fundamental assignment operator. It evaluates the expression on its right-hand side and binds the resulting object reference to the variable specified on its left-hand side.
variable = expression;

Technical Characteristics

Associativity and Evaluation Order The = operator has right-to-left associativity. The Dart compiler evaluates the right-hand expression completely before attempting to bind it to the left-hand identifier. Because the assignment operation itself returns the assigned value, right-to-left associativity enables chained assignments.
int a;
int b;
int c;

// Evaluates right-to-left: c = 5, then b = 5, then a = 5.
a = b = c = 5; 
Reference Semantics Because everything in Dart is an object (including numbers, functions, and null), variables do not store actual data payloads; they store memory references to objects. The = operator mutates the variable’s reference to point to a new object in memory. It does not perform a deep copy or duplicate the underlying object data.
List<int> listA = [1, 2, 3];
List<int> listB;

// listB now holds a reference to the exact same object in memory as listA.
listB = listA; 
Static Type Checking Dart is a statically typed language. During compilation, the = operator enforces type safety by verifying that the static type of the right-hand expression is assignable to (i.e., is a subtype of) the declared type of the left-hand variable. If the types are incompatible, the compiler throws an error.
num myNumber;
int myInteger = 10;

// Valid: 'int' is a subtype of 'num'
myNumber = myInteger; 

// Invalid: Compile-time error. 'double' is not a subtype of 'int'
// myInteger = 10.5; 
Sound Null Safety Enforcement Under Dart’s sound null safety system, the = operator strictly enforces nullability constraints. It will reject the assignment of a null literal or a nullable variable to a non-nullable variable at compile time.
String nonNullableString;
String? nullableString = null;

// Invalid: Compile-time error. Cannot assign a nullable type to a non-nullable type.
// nonNullableString = nullableString; 
Constant Initialization When used in conjunction with the const or final keywords during variable declaration, the = operator acts as an initializer rather than a standard assignment. For const, the right-hand expression must be a compile-time constant. For final and const variables, the = operator can only be applied once; subsequent reassignment attempts will result in a compile-time error.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More