dart function code example

Example 1: python function

def name():#name of the def(function);
  print("Hallo, World!")#Output is Hallo, World!;
  
name()#Name of the def, the programm will jump to the def;

#output:
#Hallo, World!

Example 2: class in dart

class class_name {  
	//rest of the code here:
}

Example 3: dart function

when you want to make a function that 
doesn't use the format return or a function that doesn't return a value
the function base will look like this:

void functionName() {

}

if its returning some thing it will look like this:

functionName() {
	
}

Example 4: dart class fields final

class Point {
  final num x;
  final num y;
  final num distanceFromOrigin;

  Point._(this.x, this.y, this.distanceFromOrigin);

  factory Point(num x, num y) {
    num distance = distanceFromOrigin = sqrt(pow(x, 2) + pow(y, 2));
    return new Point._(x, y, distance);
  }
}

Example 5: 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

Example 6: dart function syntax

sum(x, y) {
	return x + y;
}

// This is where the app starts executing.
void main() {
  print(sum(3,5)); // => 8
}