Optional Parameters with Default Values


Advertisements

Function parameters can also be assigned values by default. However, such parameters can also be explicitly passed values.

Syntax

function_name(param1,{param2= default_value}) { 
   //...... 
} 

Example

void main() { 
   test_param(123); 
}  
void test_param(n1,{s1:12}) { 
   print(n1); 
   print(s1); 
}   

It should return the following output

123 
12 

Note − All required parameters in a function must occur before optional parameters.

dart_programming_functions.htm
Advertisements