Assignment Operators

on Saturday, 18th of July, 2020

Assigning a value to a variable in Dart is done by using the = operator.

var name = "PJ"; 

Dart also supports compound operators, which are the equivalent of performing an operation and assignment.

OperatorMeaning
-=subtraction assignment
/=divisions assigment
%=modulo assignment
+=addition assignment
*=multiplication
~/=integer division assignment
>>=bitwise shift right assignment
^=bitwise XOR assignment
<<=bitwise shift left assignment
&=bitwise and assignment
|=bitwise or assignment

example:

a -= b;
// above is shorthand for
a = a - b;

// *= example
var a = 2; // Assign using =
a *= 3; // Assign and multiply: a = a * 3
assert(a == 6);


Join thousands of Flutter developers.

Sign up for infrequent updates about Flutter and Dart.

You can get all this content and more in one place. Check out my new book Flutter in Action