The operators are special symbols used to perform certain operations on operands. Dart has numerous built-in operators that can be utilized for various functions; for example, '+' is used to add two operands. Operators are designed to execute operations on one or two operands.

Precedence Table of Operators in Dart
Description | Operator | Associativity |
---|
unary postfix | expr++ expr-- () [] ?[] . ?. ! | Right |
---|
unary prefix | -expr !expr ~expr ++expr --expr await expr | Right |
---|
multiplicative | * / % ~/ | Left |
---|
additive | + - | Left |
---|
shift | << >> >>> | Left |
---|
bitwise AND | & | Left |
---|
bitwise XOR | ^ | Left |
---|
bitwise OR | | | Left |
---|
relational and type test | >= > <= < as is is! | Left |
---|
equailty | == != | Left |
---|
logical AND | && | Left |
---|
logical OR | || | Left |
---|
if-null | ?? | Left |
---|
conditional | expr ? expr2 : expr3 | Right |
---|
cascade | .. ?.. | Left |
---|
assignment | = *= /= += -= &= ^= etc. | Right |
---|
Different types of operators in Dart
The following are the various types of operators in Dart:
1. Arithmetic Operators
This class of operators contain those operators which are used to perform arithmetic operation on the operands. They are binary operators i.e they act on two operands. They go like this:
Operator Symbol | Operator Name | Operator Description |
---|
+ | Addition | Used to add two operands |
- | Subtraction | Used to subtract two operands |
-expr | Unary Minus | Used to reverse the sign of the expression |
* | Multiply | Used to multiply two operands |
/ | Division | Used to divide two operands |
~/ | Division | Used to divide two operands but give output in integer(returns quotient) |
% | Modulus | Used to give remainder of two operands(returns remainder) |
Example:
Dart
// Dart Program Demonstrating use
// Of all Arithmetic Operators
void main()
{
int a = 2;
int b = 3;
// Adding a and b
var c = a + b;
print("Sum (a + b) = $c");
// Subtracting a and b
var d = a - b;
print("Difference (a - b) = $d");
// Using unary minus
var e = -d;
print("Negation -(a - b) = $e");
// Multiplication of a and b
var f = a * b;
print("Product (a * b) = $f");
// Division of a and b
var g = b / a;
print("Division (b / a) = $g");
// Using ~/ to divide a and b
var h = b ~/ a;
print("Quotient (b ~/ a) = $h");
// Remainder of a and b
var i = b % a;
print("Remainder (b % a) = $i");
}
Output:
Sum (a + b) = 5
Difference (a - b) = -1
Negation -(a - b) = 1
Product (a * b) = 6
Division (b / a) = 1.5
Quotient (b ~/ a) = 1
Remainder (b % a) = 1
2. Relational Operators
This class of operators contain those operators which are used to perform relational operation on the operands. It goes like this:
Operator Symbol | Operator Name | Operator Description |
---|
> | Greater than | Check which operand is bigger and give result as boolean expression. |
< | Less than | Check which operand is smaller and give result as boolean expression. |
>= | Greater than or equal to | Check which operand is greater or equal to each other and give result as boolean expression. |
<= | less than equal to | Check which operand is less than or equal to each other and give result as boolean expression. |
== | Equal to | Check whether the operand are equal to each other or not and give result as boolean expression. |
!= | Not Equal to | Check whether the operand are not equal to each other or not and give result as boolean expression. |
Example:
Dart
// Dart Program Demonstrating use
// Of all Relational Operators
void main()
{
int a = 2;
int b = 3;
// Greater between a and b
var c = a > b;
print("a is greater than b (a > b) : $c");
// Smaller between a and b
var d = a < b;
print("a is smaller than b (a < b) : $d");
// Greater than or equal to between a and b
var e = a >= b;
print("a is greater than b (a >= b) : $e");
// Less than or equal to between a and b
var f = a <= b;
print("a is smaller than b (a <= b) : $f");
// Equality between a and b
var g = b == a;
print("a and b are equal (b == a) : $g");
// Unequality between a and b
var h = b != a;
print("a and b are not equal (b != a) : $h");
}
Output:
a is greater than b (a > b) : false
a is smaller than b (a < b) : true
a is greater than b (a >= b) : false
a is smaller than b (a <= b) : true
a and b are equal (b == a) : false
a and b are not equal (b != a) : true
Note: == operator can't be used to check if the object is same. So, to check if the object are same we use identical() function.
3. Type Test Operators
This class of operators contain those operators which are used to perform comparison on the operands. It goes like this:
Operator Symbol | Operator Name | Operator Description |
---|
is | is | Gives boolean value true as output if the object has specific type |
is! | is not | Gives boolean value false as output if the object has specific type |
Example:
Dart
void main()
{
String a = 'GFG';
double b = 3.3;
// Using is to compare
print(a is String);
// Using is! to compare
print(b is !int);
}
Output:
true
true
as Operator
as Operator is used for Typecasting. It performs a cast at runtime if the cast is valid else, it throws an error. It is of two types Downcasting and Type Assertion.
Example:
Dart
// Dart Program to demonstrate
// Use of as Operator
void main(){
// Declaring value
dynamic value = "Hello";
// TypeCast dynamic -> String
String str= value as String;
// Print String
print(str);
}
Output:
Hello
4. Bitwise Operators
This class of operators contain those operators which are used to perform bitwise operation on the operands. It goes like this:
Operator Symbol | Operator Name | Operator Description |
---|
& | Bitwise AND | Performs bitwise AND operation on two operands. |
| | Bitwise OR | Performs bitwise OR operation on two operands. |
^ | Bitwise XOR | Performs bitwise XOR operation on two operands. |
~ | Bitwise NOT | Performs bitwise NOT operation on one operand. |
<< | Left Shift | Shifts a in binary representation to b bits to left and inserting 0 from right. |
>> | Right Shift | Shifts a in binary representation to b bits to the right, preserving the sign bit (inserting 0 for positive numbers and 1 for negative numbers). |
>>> | Unsigned Shift right | Shifts a in binary representation to b bits to the right, inserting 0 s (ignores sign). |
Example:
Dart
// Dart Program to Demonstrate
// Use of Dart Bitwise Operators
void main()
{
print("Demonstrate use of Dart Bitwise Operators");
int a = 5;
int b = 7;
// Performing Bitwise AND on a and b
var c = a & b;
print("a & b : $c");
// Performing Bitwise OR on a and b
var d = a | b;
print("a | b : $d");
// Performing Bitwise XOR on a and b
var e = a ^ b;
print("a ^ b : $e");
// Performing Bitwise NOT on a
var f = ~a;
print("~a : $f");
// Performing left shift on a
var g = a << b;
print("a << b : $g");
// Performing right shift on a
var h = a >> b;
print("a >> b : $h");
var i = -a >>> b;
print("-a >>> b : $i");
}
Output:
Demonstrate use of Dart Bitwise Operators
a & b : 5
a | b : 7
a ^ b : 2
~a : 4294967290
a << b : 640
a >> b : 0
-a >>> b : 33554431
5. Assignment Operators
This class of operators contain those operators which are used to assign value to the operands. It goes like this:
Operator Symbol | Operator Name | Operator Description |
---|
= | Equal to | Use to assign a value to a expression or variable |
??= | Assignment operator | Assign a value only if the variable is null. |
Example:
Dart
void main()
{
int a = 5;
int b = 7;
// Assigning value to variable c
var c = a * b;
print("assignment operator used c = a*b so now c = $c\n");
// Assigning value to variable d
var d;
// Value is assign as it is null
d ??= a + b;
print("Assigning value only if d is null");
print("d??= a+b so d = $d \n");
// Again trying to assign value to d
d ??= a - b;
// Value is not assign as it is not null
print("Assigning value only if d is null");
print("d??= a-b so d = $d");
print("As d was not null value was not updated");
}
Output:
assignment operator used c = a*b so now c = 35
Assigning value only if d is null
d??= a+b so d = 12
Assigning value only if d is null
d??= a-b so d = 12
As d was not null value was not updated
Compound Assignment Operator
Apart from there is another way where we can use a operator that is compound assignment operator where we combine an operator with an assignment operatorso to shorten the steps and make code more effective.

Example:
a+=1;
// The above statement is same as
// the statement mentioned below
a=a+1;
6. Logical Operators
This class of operators contain those operators which are used to logically combine two or more conditions of the operands. It goes like this:
Operator Symbol | Operator Name | Operator Description |
---|
&& | And Operator | Returns true only if both conditions are true. |
|| | Or Operator | Returns true if at least one condition is true. |
! | Not Operator | Reverses the boolean value of an expression. |
Example 1 :
Dart
void main()
{
int a = 5;
int b = 7;
// Using And Operator
bool c = a > 10 && b < 10;
print(c);
// Using Or Operator
bool d = a > 10 || b < 10;
print(d);
// Using Not Operator
bool e = !(a > 10);
print(e);
}
Output:
false
true
true
Note: Logical operator can only be application to boolean expression and in dart, non-zero numbers are not considered as true and zero as false
Example 2 : (Incorrect Way)
Dart
void main()
{
int a = 5;
int b = 7;
// Using And Operator
print(a && b);
// Using Or Operator
print(a || b);
// Using Not Operator
print(!a);
}
Output:
compileDDC
main.dart:7:15: Error: A value of type 'int' can't be assigned to a variable of type 'bool'.
print(a && b);
^
main.dart:7:20: Error: A value of type 'int' can't be assigned to a variable of type 'bool'.
print(a && b);
^
main.dart:10:15: Error: A value of type 'int' can't be assigned to a variable of type 'bool'.
print(a || b);
^
main.dart:10:20: Error: A value of type 'int' can't be assigned to a variable of type 'bool'.
print(a || b);
^
main.dart:13:16: Error: A value of type 'int' can't be assigned to a variable of type 'bool'.
print(!a);
Example 3 : (Correct Way)
Dart
// Dart Program to demonstrate use of
// Logical Operators
void main()
{
var a = true;
var b = false;
// Printing the Values of a & b
print("a: $a , b: $b\n");
// Using And Operator
print("a && b = ${a&&b}");
// Using Or Operator
print("a || b = ${a||b}");
// Using Not Operator
print("!a = ${!a}");
}
Output:
a: true , b: false
a && b = false
a || b = true
!a = false
7. Conditional Operators
This class of operators contain those operators which are used to perform comparison on the operands. It goes like this:
Operator Symbol | Operator Name | Operator Description |
---|
condition ? expression1 : expersion2 | Conditional Operator | A shorter version of if-else. If condition is true, executes expr1; otherwise, executes expr2 |
expersion1 ?? exppression2 | Conditional Operator | If expr1 is non-null, returns its value; otherwise, returns expr2. |
Example:
Dart
void main()
{
int a = 5;
// Conditional Statement
var c = (a < 10) ? "Statement is Correct, Geek" : "Statement is Wrong, Geek";
print(c);
// Conditional statement
int? n;
// Warning: Operand of null-aware operation '??' has type 'int' which excludes null.
// For batter practice make both same type to avoid warning
// var d = n ?? 10;
var d = n ?? "n has Null value";
print(d);
// After assigning value to n
n = 10;
// we make it all ready null safe
//d = n ? ? "n has Null value";
d = n;
print(d);
}
Output:
Statement is Correct, Geek
n has Null value
10
Note: Also In The Above Code,You May Notice That The Variable 'n' is Declared As "int? n".By declaring n as int?, you are indicating that the variable n can hold an integer value or a null value. The ? denotes that the variable is nullable, meaning it can be assigned a null value in addition to integer values.
8. Cascade Notation Operators:
This class of operators allows you to perform a sequence of operation on the same element. It allows you to perform multiple methods on the same object. It goes like this:
Operator Symbol | Operator Name | Operator Description |
---|
.. | Cascading Method | Used to perform multiple method calls or property assignments on the same object. |
..? | Null Shorting Cascade | Used to perform multiple operations on an object only if it is not null. Prevents null reference errors |
Example:
Dart
// Dart Program to Demonstrate
// Use of Cascading Operator
// Class
class GFG {
int? a;
int? b;
void set(int x, int y) {
this.a = x;
this.b = y;
}
void add() {
if (a != null && b != null) { // Null safety check
var z = a! + b!;
print(z);
} else {
print("Values are not initialized.");
}
}
}
void main() {
// Creating objects of class GFG
GFG geek1 = GFG();
GFG geek2 = GFG();
// Without using Cascade Notation
geek1.set(1, 2);
geek1.add();
// Using Cascade Notation
geek2
..set(3, 4)
..add();
}
Output:
3
7
To know more about Dart please check Dart Tutorial
Similar Reads
Dart Tutorial Dart is an open-source general-purpose programming language developed by Google. It supports application development on both the client and server side. However, it is widely used for the development of Android apps, iOS apps, IoT(Internet of Things), and web applications using the Flutter Framework
7 min read
Basics
Data Types
Dart - Data TypesLike other languages (C, C++, Java), whenever a variable is created, each variable has an associated data type. In Dart language, there are the types of values that can be represented and manipulated in a programming language. In this article, we will learn about Dart Programming Language Data Types
8 min read
Basics of Numbers in DartLike other languages, Dart Programming also supports numerical values as Number objects. The number in Dart Programming is the data type that is used to hold the numeric value. Dart numbers can be classified as: int (Integer) The int data type is used to represent whole numbers.Declaring Integer in
6 min read
Strings in DartA Dart string is a sequence of UTF-16 code units. With the same rule as that of Python, you can use either single or double quotes to create a string. The string starts with the datatype String or Var : String string = "I love GeeksforGeeks";var string1 = 'GeeksforGeeks is a great platform for upgra
6 min read
Dart - SetsSets in Dart is a special case in List, where all the inputs are unique i.e. it doesn't contain any repeated input. It can also be interpreted as an unordered array with unique inputs. The set comes into play when we want to store unique values in a single variable without considering the order of t
6 min read
Dart Programming - MapIn Dart programming, Maps are dictionary-like data types that exist in key-value form (known as lock-key). There is no restriction on the type of data that goes in a map data type. Maps are very flexible and can mutate their size based on the requirements. However, it is important to note that all l
7 min read
Queues in DartDart also provides the user to manipulate a collection of data in the form of a queue. A queue is a FIFO (First In First Out) data structure where the element that is added first will be deleted first. It takes the data from one end and removes it from the other end. Queues are useful when you want
3 min read
Data Enumeration in DartEnumerated types (also known as enumerations or enums) are primarily used to define named constant values. The enum keyword is used to define an enumeration type in Dart. The use case of enumeration is to store finite data members under the same type definition. Declaring enumsenum variable_name{ //
3 min read
Control Flow
Key Functions
Dart - Anonymous FunctionsAn anonymous function in Dart is like a named function but they do not have names associated with it. An anonymous function can have zero or more parameters with optional type annotations. An anonymous function consists of self-contained blocks of code and that can be passed around in our code as a
2 min read
Dart - main() FunctionThe main() function is a predefined method in Dart. It is the most important and mandatory part of any dart program. Any dart script requires the main() method for its execution. This method acts as the entry point for any Dart application. It is responsible for executing all library functions, user
2 min read
Dart - Common Collection MethodsList, Set, and Map share common functionalities found in many collections. Some of this common functionality is defined by the Iterable class, which is implemented by both List and Set.1. isEmpty() or isNotEmptyUse isEmpty or isNotEmpty to check whether a list, set, or map has items or not.Example:D
2 min read
How to Exit a Dart Application Unconditionally?The exit() method exits the current program by terminating the running Dart VM. This method takes a status code. A non-zero value of status code is generally used to indicate abnormal termination. This is a similar exit in C/C++, Java. This method doesn't wait for any asynchronous operations to term
2 min read
Dart - Getters and SettersGetters and Setters, also called accessors and mutators, allow the program to initialize and retrieve the values of class fields respectively. Getters or accessors are defined using the get keyword.Setters or mutators are defined using the set keyword.A default getter/setter is associated with every
3 min read
Dart - Classes And ObjectsDart is an object-oriented programming language, so it supports the concept of class, object, etc. In Dart, we can define classes and objects of our own. We use the class keyword to do so. Dart supports object-oriented programming features like classes and interfaces.Let us learn about Dart Classes
4 min read
Object-Oriented Programming
Dart - this keywordthis keyword represents an implicit object pointing to the current class object. It refers to the current instance of the class in a method or constructor. The this keyword is mainly used to eliminate the ambiguity between class attributes and parameters with the same name. When the class attributes
2 min read
Dart - Static KeywordThe static keyword is used for the memory management of global data members. The static keyword can be applied to the fields and methods of a class. The static variables and methods are part of the class instead of a specific instance. The static keyword is used for a class-level variable and method
3 min read
Dart - Super and This keywordSuper Keyword in DartIn Dart, the super keyword is used to refer immediate parent class object. It is used to call properties and methods of the superclass. It does not call the method, whereas when we create an instance of subclass than that of the parent class is created implicitly so super keywor
4 min read
Dart - Concept of InheritanceIn Dart, one class can inherit another class, i.e. dart can create a new class from an existing class. We make use of extend keyword to do so.Terminology: Parent Class: It is the class whose properties are inherited by the child class. It is also known as a base class or super class.Child Class: It
5 min read
Instance and class methods in DartDart provides us with the ability to create methods of our own. The methods are created to perform certain actions in class. Methods help us to remove the complexity of the program. It must be noted that methods may or may not return any value, and also, they may or may not take any parameter as inp
3 min read
Method Overriding in DartMethod overriding occurs in Dart when a child class tries to override the parent class's method. When a child class extends a parent class, it gets full access to the methods of the parent class and thus it overrides the methods of the parent class. It is achieved by re-defining the same method pres
3 min read
Getter and Setter Methods in DartGetter and Setter methods are class methods used to manipulate the data of class fields. Getter is used to read or get the data of the class field, whereas setter is used to set the data of the class field to some variable. The following diagram illustrates a Person class that includes: A private va
2 min read
Abstract Classes in DartAn abstract class in Dart is defined as a class that contains one or more abstract methods (methods without implementation). To declare an abstract class, we use the abstract keyword. It's important to note that a class declared as abstract may or may not include abstract methods. However, if a clas
4 min read
Dart - Builder ClassIn Flutter, each widget has an associated build method responsible for rendering the UI. The Flutter framework automatically provides a BuildContext parameter to the build method.Widget build ( BuildContext context )Flutter takes care that there need not be any Widget apart from the build that needs
4 min read
Concept of Callable Classes in DartDart allows the user to create a callable class which allows the instance of the class to be called as a function. To allow an instance of your Dart class to be called like a function, implement the call() method. Syntax :class class_name { ... // class content return_type call ( parameters ) { ...
4 min read
Interface in DartThe interface in the dart provides the user with the blueprint of the class, which any class should follow if it interfaces that class, i.e., if a class inherits another, it should redefine each function present inside an interfaced class in its way. They are nothing but a set of methods defined for
3 min read
Dart - extends Vs with Vs implementsAll developers working with Dart for application development using the Flutter framework regularly encounter different usages of the implements, extends, and keywords. In Dart, one class can inherit another class, i.e. , Dart can create a new class from an existing class. We make use of keywords to
4 min read
Dart - Date and TimeA DateTime object is a point in time. The time zone is either UTC or the local time zone. Accurate date-time handling is required in almost every data context. Dart has the marvelous built-in classes for date time and duration in dart:core. Key Uses of DateTime in Dart:Comparing and Calculating Date
3 min read
Using await async in DartThe async and await approaches in Dart are very similar to other languages, which makes it a comfortable topic to grasp for those who have used this pattern before. However, even if you donât have experience with asynchronous programming using async/await, you should find it easy to follow along her
4 min read
Dart Utilities
Dart Programs
Dart - Sort a ListThe List data type is similar to arrays in other programming languages. A list is used to represent a collection of objects. It is an ordered group of objects. The core libraries in Dart are responsible for the existence of the List class, its creation, and manipulation. Sorting of the list depends
2 min read
Dart - String toUpperCase() Function with ExamplesThe string toUpperCase() method converts all characters of the string into an uppercase letter. The string toUpperCase() function returns the string after converting all characters of the string into the uppercase letter. Syntax: Str.toUpperCase()Parameter: The string toUpperCase() function doesn't
1 min read
Dart - Convert All Characters of a String in LowercaseWith the help of the toLowerCase() method in the string will convert all the characters in a string in lowercase.Syntax: String.toLowerCase() Return: string Image Representation: Example 1: Dart// main function start void main() { // initialise a string String st = "GEEKSFORGEEKS"; // print the stri
1 min read
How to Replace a Substring of a String in Dart?To replace all the substrings of a string, we make use of the replaceAll method in Dart. This method replaces all the substrings in the given string with the desired substring. Returns a new string in which the non-overlapping substrings matching from (the ones iterated by from.allMatches(this Strin
2 min read
How to Check String is Empty or Not in Dart (Null Safety)?We can check a string is empty or not by the String Property isEmpty. If the string is empty then it returns True if the string is not empty then it returns False.Syntax: String.isEmpty Return : True or False.Image Representation: Example 1:Dart// main function start void main() { // initialise a st
1 min read
Exception Handling in DartAn exception is an error that occurs inside the program. When an exception occurs inside a program, the normal flow of the program is disrupted, and it terminates abnormally, displaying the error and exception stack as output. So, an exception must be taken care of to prevent the application from te
3 min read
Assert Statements in DartAs a programmer, it is very necessary to make an errorless code is very necessary and to find the error is very difficult in a big program. Dart provides the programmer with assert statements to check for the error. The assert statement is a useful tool to debug the code, and it uses a Boolean condi
3 min read
Fallthrough Condition in DartFall through is a type of error that occurs in various programming languages like C, C++, Java, Dart ...etc. It occurs in switch-case statements where when we forget to add break statement and in that case flow of control jumps to the next line. "If no break appears, the flow of control will fall th
3 min read
Concept of Isolates in DartDart was traditionally designed to create single-page applications. We also know that most computers, even mobile platforms, have multi-core CPUs. To take advantage of all those cores, developers traditionally use shared-memory threads running concurrently. However, shared-state concurrency is error
2 min read
Advance Concepts