In dart, the first function that gets executed is your main function such as:

void main(){

   // your code

}

 

main is a special function and the keyword main is reserved in dart so you can't use it as a name for other functions or variables.

we can define our own function by giving it a name and parameters if there are any.

the conventional case for naming dart functions is a camel case where the first letter is lower cased e.g cammeCase, addNumbers, getCards

e.g:

double addNumbers(double num1, double num2){

    return num1 + num2;

}

 

the keyword double before addNumbers indicates what type of result, this function will return and in this case, it will return a type of double which basically means decimal numbers, we could have used int or num where int does not allow decimal numbers and num would allow both int and double.

Also, note that I've used double before num1 and num2, this forces the user to use the function with the correct type of data and in this case, this function will only accept the type of double, decimal numbers.

the code after the keyword return is the result of the function once it's called.

 

 

e.g

void main(){

     print(addNumbers(1.2, 2.3));

 

}

 

and when we run the code above, 3.5 will be printed to the console.

 

 

main is a special function in dart because main is the entry point of a dart application. 

In dart, all codes need to be placed inside void main(){} in order to run. 

 

in other words when you put void main () {} in your flutter or dart app, this will be the first function that gets executed automatically.