• Guides
    • Getting started with Dart
  • Blog
  • FAQ
    • Dart
    • Flutter
  • Contact
  • Guides
    • Getting started with Dart
  • Blog
  • FAQ
    • Dart
    • Flutter
  • Contact
  • Getting Started with Dart
    • Dart Variables
    • Dart Operators
    • Dart Comments
  • Dart Data Types
    • Dart Strings
    • Dart Numbers
    • Dart Booleans
    • Dart Lists
    • Dart Maps
  • Control Flow
    • Dart if...else Statements
    • Dart switch Statement
    • Dart for Loop
    • Dart for...in Loop
    • Dart while and do...while Loops
    • break and continue Statements
  • Dart Functions
  • Dart Classes
  • Dart Objects
  • Dart Constructors
  • Dart Exceptions

Dart Operators

463 views 0

Written by Ajaya Shrestha
December 28, 2021

In this chapter, we will learn about different Dart Operators that are available in dart.


Dart Operators

Operators are symbols that are used to perform certain operations. For example,

5 - 3;

Here – is the operator and 5 and 3 are the operands.

– operator is used to subtract the value from 5 and 3, which results in 2.


Dart Operator Types

Dart supports all the operators that are available in modern programming languages.

  • Arithmetic Operators
  • Comparison Operators
  • Assignment Operators
  • Type test Operators
  • Bitwise Operators
  • Logical Operators
  • Conditional Operators

Dart Arithmetic Operators

Arithmetic operators help in performing arithmetic operations. For example,

void main() {

int num = 5 - 3;

print(num); // 2

}

Here, – operator is used to subtract value 3 from value 5, which results in 2.

OperatorNameDescription
+AdditionAdds two operands
–SubtractionSubtracts two operands
-exprUnary MinusReverse the sign of the expression
*MultiplyMultiply two operands
/DivisionDivide two operands
~/DivisionDivide two operands and give integer output
%ModulusGive reminder of two operands
++IncrementIncrements the value by 1
– – DecrementDecrements the value by 1

Arithmetic Operators Examples

void main() {

var num1 = 3 + 4; // 7

var num2 = 4 - 3; // 1

var num3 = 4 * 3; // 12

var num4 = 4 / 3; // 1.3333333333333333

var num5 = 4 ~/ 3; // 1

var num6 = 4 % 3; // 1

}

Dart Comparison Operators

Comparison operators help in comparing two operands and give boolean results true or false. For example,

void main() {

var num = 5 > 3;

print(num); // true

}
OperatorNameDescription
==EqualTrue if both operands are equal
!=Not EqualTrue if both operands are not equal
>Greater thanTrue if left operand is greater than right operand
<Less thanTrue if left operand is less than right operand
>=Greater than or equalTrue if left operand is greater than or equal to right operand
<=Less than or equalTrue if left operand is less than or equal to right operand

Comparison Operators Examples

void main() {

var num1 = 3 < 4; // true

var num2 = 4 > 3; // false

var num3 = 3 >= 3; // true

var num4 = 3 <= 3; // true

var num5 = 3 == 3; // true

var num6 = 4 != 3; // true

}

Dart Assignment Operators

Assignment operator help is assigning a value to a variable. For example,

var num = ‘hello’;
OperatorNameDescription
=AssignmentAssign values to variable
-=Subtraction AssignmentAssign value after subtraction
+=Addition AssignmentAssign value after addition
/=Division AssignmentAssign value after division
%=Modulus AssignmentAssign value after modulus
*=Multiply AssignmentAssign value after multiplication
~/=Integer Division AssignmentAssign value after integer division

Assignment Operators Examples

void main() {

var num1 = 5; // 5

var num1 -= 4; // num1 = num1 - 4

var num3 +=4; // num1 = num1 + 4

var num4 /= 5; // num1 = num1 / 5

var num5 *= 5; // num1 = num * 5

}

Type Test Operators

Type test operators help in comparing the operands. For example,

void main()

{

    String a = 'hello';

    int b = 3;

 

    print(a is String); // true

    print(b is !int); // false

}
OperatorNameDescription
isisTrue if specified data type
is!is notTrue if not specified data type

Dart Bitwise Operators

Bitwise operators help in performing bitwise operations. For example,

void main()

{

    int a = 3;

    int b = 2;

 

    // Bitwise AND

    var c = a & b;

    print(c); // 2 

}
OperatorNameDescription
&ANDAND operation on two operands
|OROR operation on two operands
^XORXOR operation on two operands
~exprUnary bitwise complement0s become 1s; 1s become 0s
<<Shift LeftShifts a in binary representation to b bits to left and inserting 0 from right.
>>Shift RightShifts a in binary representation to b bits to left and inserting 0 from left.

Dart Logical Operators

Logical operators help in performing logical operations and return a boolean value. For example,

void main()

{

    int a = 7;

    int b = 2;

 

    // And Operator

    bool c = a > 10 && b < 10;

    print(c); // false

}
OperatorNameDescription
&&ANDTrue if both the operands are true
||ORTrue if either of the operands is true
!NOTTrue if the operand is false

That’s it for the operators. In the next chapter, we will learn about the Dart Comments and how we can use them in our program.

Was this helpful?

Yes  1 No
Related Articles
  • Dart Constructors
  • Dart Exceptions
  • Dart Objects
  • Dart Classes
  • Control Flow
  • Dart Functions
Previously
Dart Variables
Up Next
Dart Comments
flutter-dev-experts




FLUTTERGUIDE
FlutterGuide is an easy learning guide platform to help you build apps for any screen. The leading Dart/Flutter guides for getting started and become pro.
Guides
  • Getting started with Dart 22
  • Private Documentation 1
Categories
  • Firebase
  • Dart
  • iOS
  • API
  • Bloc
  • Flutter
  • Widgets
  • Mobile
  • State Management
  • Design
  • Animations
  • Flutter Designs
About
About Us
Guides
Blogs
FAQs
Contact
  • Privacy Policy
  • Terms & Conditions
  • Copyright 2022 Fawesome Apps. All Rights Reserved