Skip to main content
Named parameters are function arguments explicitly bound to a parameter identifier at the call site, rather than relying on their ordinal position in the argument list. In Dart, they are declared by enclosing the parameter definitions within curly braces {} in the function signature.

Syntax and Declaration

To define named parameters, place them inside {} at the end of the parameter list. At the call site, they are invoked using the parameterName: value syntax.

Technical Characteristics

1. Optionality and Nullability By default, all named parameters are optional. Because they can be omitted during invocation, Dart’s sound null safety requires that an optional named parameter must either be declared as a nullable type (using the ? suffix) or be assigned a default value. 2. Default Values Default values are assigned using the = operator in the function signature. The assigned default value must be a compile-time constant.
3. The required Modifier To mandate that a caller provides a specific named parameter, prefix the parameter declaration with the required keyword. A required named parameter bypasses the default optionality rule, meaning it does not need to be nullable or possess a default value, as the analyzer guarantees its presence at compile time.
4. Ordering and Interleaving At the call site, named arguments can be passed in any arbitrary order, completely independent of their declaration order in the function signature. Furthermore, as of Dart 2.17, named arguments can be interleaved with positional arguments at the call site, provided the positional arguments maintain their strict ordinal sequence.
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More