In this guide, we will discuss Optional Named Parameter in Dart Programming Language. Unlike positional parameters, the parameters’ name must be specified while the value is being passed. Curly brace {} can be used to specify optional named parameters.
Syntax – Declaring the function
void function_name(a, {optional_param1, optional_param2}) { }
Syntax – Calling the function
function_name(optional_param:value,…);
Example
void main() { test_param(123); test_param(123,s1:'hello'); test_param(123,s2:'hello',s1:'world'); } test_param(n1,{s1,s2}) { print(n1); print(s1); }
It should produce the following output−
123 null 123 hello 123 world
Next Topic : Click Here
Pingback: Optional Positional Parameter | Adglob Infosystem Pvt Ltd
Pingback: Dart Programming - Functions | Adglob Infosystem Pvt Ltd