Search
 
SCRIPT & CODE EXAMPLE
 

DART

dart operators

// first individual use

void main() {
  int x = 5;
  int y = 2;
  int z = x + y; // collection operator
  int z = x - y; // extraction operator
  int z = x * y; // impact operator
  int z = x / y; // divide operator
  
}

// seconds if else operators

void main() {
   int x = 2;
   int y = 5;
   if(x == y) {} // equality operator
   if(x < y) {} // less than sign operator
   if(x > y) {} // greater operator
   if(x <= y) {} // less than sign or equality operator
   if(x >= y) {} // greater or equality operator
}

// I guess that's enough for now, good coding <3
Comment

operators in dart

Dart supports the following types of operators.

1.Arithmetic Operators
2.Assignment Operators
3.Relational Operators
4.Type test Operators
5.Logical Operators
6.Bitwise Operator
7.Conditional Operators
8.Casecade notation(..) Operators


1.Dart Arithmetic Operators

Example -
void main(){  
  print("Example of Assignment operators");  
  var n1 = 10;  
  var n2 = 5;  
    
  print("n1+n2 = ${n1+n2}");  
  print("n1-n2 = ${n1-n2}");  
  print("n1*n2 = ${n1*n2}");  
  print("n1/=n2 = ${n1/n2}");   
  print("n1%n2 = ${n1%n2}");     
} 

Output:
Example of Arithmetic operators 
n1+n2 = 15 
n1-n2 = 5 
n1*n2 = 50 
n1/=n2 = 2 
n1%n2 = 0

2. Unary Operators (post and pre)

Example -
void main() {   
   var x = 30;   
   print(x++);                  //The postfix value  
     
var y = 25;  
print(++y);                 //The prefix value,  
         
var z = 10;  
print(--z);                  //The prefix value  
  
var u = 12;                                           
   print(u--);     //The postfix value  
}          
   
Output:
30
26
9
12

3. Assignment Operator

Example -
void main(){  
 print("Example of Assignment operators");  
    
  var n1 = 10;  
  var n2 = 5;  
    
  n1+=n2;  
  print("n1+=n2 = ${n1}");  
    
  n1-=n2;  
  print("n1-=n2 = ${n1}");  
    
  n1*=n2;  
  print("n1*=n2 = ${n1}");  
    
  n1~/=n2;  
  print("n1~/=n2 = ${n1}");  
  n1%=n2;  
  print("n1%=n2 = ${n1}");    
}  

Output:
Example of Assignment operators 
n1+=n2 = 15 
n1-=n2 = 10 
n1*=n2 = 50 
n1~/=n2 = 10 
n1%=n2 = 0 

4. Relational Operator

Example -
void main() {   
var a = 30;  
var b = 20;  
  
print("The example of Relational Operator");  
  
var res = a>b;  
print("a is greater than b: "+res. toString());  // We will learn the toString in next tutorial  
  
var res0 = a<b;  
print("a is less than b: "+res0. toString());  
  
var res1 = a>=b;  
print("a is greater than or equal to b: "+res1. toString());  
  
var res2 = a<=b;  
print("a is less than and equal to b: "+res2. toString());  
  
var res3 = a!= b;  
print("a is not equal to  b: "+res3. toString());  
  
var res4 = a==b;  
print("a is  equal to  b: "+res4. toString());  
}  

Output:
The example of Relational Operator
a is greater than b: true
a is less than b: false
a is greater than or equal to b: true
a is less than and equal to b: false
a is not equal to  b: true
a is  equal to  b: false

5. Type Test Operators

Example:
void main()  
{  
  var num = 10;  
  var name = "JavaTpoint";  
  print(num is int);    
  print(name is! String );  
} 

Output:
true
false

6. Logical Operators

Example:
void main(){  
  bool bool_val1 = true, bool_val2 = false;   
  print("Example of the logical operators");  
    
  var val1 = bool_val1 && bool_val2;  
  print(val1);  
    
  var val2 = bool_val1 || bool_val2;  
  print(val2);  
    
  var val3 = !(bool_val1 || bool_val2);  
  print(val3);   
}  

Output:
false 
true 
false

7. Bitwise Operators

Example -
void main(){  
  print("Example of Bitwise operators");  
    
  var a  = 25;  
  var b = 20;  
  var c = 0;  
    
  // Bitwise AND Operator  
  print("a & b = ${a&b}");  
    
  // Bitwise OR Operator  
  print("a | b = ${a|b}");  
    
  // Bitwise XOR  
  print("a ^ b = ${a^b}");  
    
  // Complement Operator  
  print("~a = ${(~a)}");  
    
  // Binary left shift Operator  
  c = a <<2;  
  print("c<<1= ${c}");  
    
  // Binary right shift Operator  
  c = a >>2;  
  print("c>>1= ${c}");  
}  

Output:
a & b = 16
 a | b = 29
 a ^ b = 13
 ~a = 4294967270
 c<<1= 100
 c>>1= 6

8. Conditional Operators (?:)

Example -
void main() {   
   var x = null;   
   var y = 20;   
   var val = x ?? y;   
   print(val);   
}  

Output:
20
Comment

or operator in dart

var a = 10 
var result = ( a>5 || a<10)
Comment

dart ?? operator

String? foo = null;

print(foo ?? " its empty");//output: ' its empty'

foo = "foo";

print(foo ?? " its empty");//output: "foo"
Comment

dart is operator

void main() {
  
  dynamic variable = "hello";
  
  if(variable is String) {
    print("is a String");
  } else {
    print("is not String");
  }
 
  if(variable is int) {
    print("is a int");
  } else {
    print("is not int");
  }
    
}
Comment

dart .. operator

void main() {
  Person()
    ..name = "John"
    ..age = 30
    ..sex = "Male"
    ..describeMyself();
}

class Person {
  String? name;
  int? age;
  String? sex;

  Person({this.name, this.age, this.sex});

  void describeMyself() {
    print('Hello my name is $name, I am $age years old');
  }
}
Comment

dart operator ??

String? foo = null;

print(foo ?? " its empty");//output: ' its empty'

foo = "foo";

print(foo ?? " its empty");//output: "foo"
Comment

dart ?? operator

??

Called also null operator. This operator returns expression on its left, except if it is null, and if so, it returns right expression:

void main() {
  print(0 ?? 1);  // <- 0
  print(1 ?? null);  // <- 1
  print(null ?? null); // <- null
  print(null ?? null ?? 2); // <- 2
}

Comment

PREVIOUS NEXT
Code Example
Dart :: check if animation complete in flutter 
Dart :: flutter signing the app 
Dart :: tab splash hide flutter 
Dart :: how to mesure execution time of method in dart 
Dart :: dart zip two lists 
Dart :: what is shouldshowrequestpermissionrationale return 
Dart :: proportion in flutter 
Dart :: flutter webview platform._operatingsystem 
Dart :: dart list slice 
Dart :: * In pubspec.yaml the flutter.plugin.{androidPackage,iosPrefix,pluginClass} keys are deprecated. Instead use the flutter.plugin.platforms key introduced in Flutter 1.10.0 
Dart :: Cannot remove from an unmodifiable list dart 
Dart :: flutter padding symmetric 
Dart :: Should I learn Dart for Flutter? 
Swift :: delay code execution swift 5 
Swift :: How do I check if a string contains another string in Swift 
Swift :: swift array to string 
Swift :: swift 5 btn change image 
Swift :: get hours difference between two dates swift 
Swift :: swift get a rectangle centered 
Swift :: fizzbuzz in swift 
Swift :: fetch codable from userdefaults ios swift 
Swift :: swift clear user defaults 
Swift :: get keyboard height swift 
Swift :: swift date difference in days 
Swift :: string to swift 2022 
Swift :: swift array contains 
Swift :: how to set the stack color in swiftui 
Swift :: user defaults swift 
Swift :: Swift Nested function 
Swift :: swift check if regex is in string 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =