flutter named parameters code example

Example 1: ~/ vs / dart

assert(2 + 3 == 5);
assert(2 - 3 == -1);
assert(2 * 3 == 6);
assert(5 / 2 == 2.5); // Result is a double
assert(5 ~/ 2 == 2); // Result is an int
assert(5 % 2 == 1); // Remainder

assert('5/2 = ${5 ~/ 2} r ${5 % 2}' == '5/2 = 2 r 1');

Example 2: Flutter Constructor

Customer(String name, int age, String location) {
  this.name = name;
  this.age = age;
  this.location = location;
}

Customer(this.name, this.age) {
  this.name = name;
  this.age = age;
}

Example 3: dart ?? operator

int val1;
final int val2 = 20;

console.log(val1 ?? val2); //result => 20 because val1 is null

----------------------------------

final int val1 = 30;
final int val2 = 20;

console.log(val1 ?? val2); //result => 30 because val1 is not null