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 :: get HH:MM time in flutter 
Dart :: splash screen flutter null safety 
Dart :: flutter close window 
Dart :: dart create hash 
Dart :: upload zip file to ec2 
Dart :: Error: java.io.IOException: No such file or directory in android 11 
Dart :: flutter appbar hide 
Dart :: loop map flutter 
Dart :: Flutter: How do you make a card clickable? 
Dart :: flutter convert list dynamic to list string 
Dart :: onetime onboarding flutter 
Dart :: if else dart example 
Dart :: increase widh of TableCell in flutter 
Dart :: Flutter - FlutterLogo Widget 
Dart :: remove .0 flutter 
Dart :: @override dart 
Dart :: dart typedef 
Dart :: is init state executed when returning with navigator flutter 
Dart :: load svg in imageprovider flutter 
Dart :: dart data structures 
Dart :: Single document from firestore to a dart object 
Dart :: Remove space between widgets in row flutter 
Dart :: glowing buttons in flutter 
Dart :: parse string to datetime 
Swift :: Detect if device is ipad or iphone swift 
Swift :: how to remove background color for uibutton swift 
Swift :: Add UIToolBar to all keyboards 
Swift :: remove back button swift 
Swift :: swift how to sort array 
Swift :: swiftui tabview 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =