Interview frequency: …
Short answer
Named parameters are passed by name and make the intent clear, while positional optional parameters depend on their order and can have a default value.
Explanation
Use named parameters when readability and distinction matter more, especially with more than one optional option. A named parameter can be made required with required, and a default value can be given to an optional positional or named parameter. A good signature design reduces passing values in an order that is hard to review.
Code example
void greet(String name, {String punctuation = "!"}) {
print("Hello $name$punctuation");
}
greet("Dart", punctuation: ".");Common mistakes
- Treating every named parameter as optional; required changes that.
- Overusing positional parameters, making the function call unclear.