Understanding Dart operators and expressions is essential for writing effective and clean code in Flutter and Dart-based apps. Dart provides a variety of operators to perform mathematical calculations, comparisons, and logical evaluations. These include arithmetic, relational, logical, bitwise, assignment, and type test operators.

Below is a complete example that demonstrates various Dart operators in action:
void main() {
int a = 10;
int b = 5;
// Arithmetic Operators
print('Addition: ${a + b}');
print('Subtraction: ${a - b}');
print('Multiplication: ${a * b}');
print('Division: ${a / b}');
print('Modulus: ${a % b}');
// Relational Operators
print('Equal: ${a == b}');
print('Not Equal: ${a != b}');
print('Greater Than: ${a > b}');
print('Less Than: ${a < b}');
// Logical Operators
bool x = true;
bool y = false;
print('AND: ${x && y}');
print('OR: ${x || y}');
print('NOT: ${!x}');
// Assignment Operators
int c = a;
c += b;
print('c after += : $c');
// Type Test Operators
print('Is int: ${a is int}');
print('Is not String: ${a is! String}');
}
void main() {
int a = 10;
int b = 5;
// Arithmetic Operators
print('Addition: ${a + b}');
print('Subtraction: ${a - b}');
print('Multiplication: ${a * b}');
print('Division: ${a / b}');
print('Modulus: ${a % b}');
// Relational Operators
print('Equal: ${a == b}');
print('Not Equal: ${a != b}');
print('Greater Than: ${a > b}');
print('Less Than: ${a < b}');
// Logical Operators
bool x = true;
bool y = false;
print('AND: ${x && y}');
print('OR: ${x || y}');
print('NOT: ${!x}');
// Assignment Operators
int c = a;
c += b;
print('c after += : $c');
// Type Test Operators
print('Is int: ${a is int}');
print('Is not String: ${a is! String}');
}
void main() { int a = 10; int b = 5; // Arithmetic Operators print('Addition: ${a + b}'); print('Subtraction: ${a - b}'); print('Multiplication: ${a * b}'); print('Division: ${a / b}'); print('Modulus: ${a % b}'); // Relational Operators print('Equal: ${a == b}'); print('Not Equal: ${a != b}'); print('Greater Than: ${a > b}'); print('Less Than: ${a < b}'); // Logical Operators bool x = true; bool y = false; print('AND: ${x && y}'); print('OR: ${x || y}'); print('NOT: ${!x}'); // Assignment Operators int c = a; c += b; print('c after += : $c'); // Type Test Operators print('Is int: ${a is int}'); print('Is not String: ${a is! String}'); }
For a more advanced breakdown of Dart expressions and operator precedence, refer to the official Dart Language Tour.
Operators are fundamental in any programming language, and mastering them in Dart gives you the flexibility to write clean, efficient, and bug-free code.