Dart – Optional parameters

Dart has two types of optional parameters: named and positional

A parameter wrapped by [ ] is a positional optional parameter.
A parameter wrapped by { } is a names optional parameter.

Example with positional optional parameter:

function1 (String name, [int age = 31]) {

}

Calling function1:

- function1('Smith');
- function1('Smith', 48);


Example with names optional parameter:

function2(String name, {int age = 31}) {

}

Calling function2:

- function2('Lars');
- function2('Lars', alder: 48);

Note: You may use positional optional parameters or named optional parameters,
but not both in the same function or method.