Back to results for “Fundamentals”
Flutter › Dart Language Basics & Syntax

What are named parameters and positional parameters in Dart functions, and how does using curly braces to declare parameters as named improve the readability of a function call with many arguments?

Intermediate

Answer

Dart functions can accept parameters either positionally, meaning arguments must be passed in a fixed specific order matching the function's declaration, or as named parameters, declared using curly braces, which lets a caller explicitly specify each individual argument's own corresponding name when calling the function, and named parameters are especially valuable for functions accepting many different parameters, since explicitly naming each argument at the actual call site makes the resulting code significantly more self documenting and considerably harder to accidentally call with arguments passed in the wrong order.
void createUser({required String name, required int age, String? email}) {
  print('$name is $age years old');
}

createUser(name: 'Alex', age: 30);
Real-world example A function for creating a new user account uses named parameters for name, age, and an optional email, making a call site like createUser(name: Alex, age: 30) immediately self explanatory, compared to an equivalent purely positional call that would be far more difficult to correctly interpret at a glance.

Common follow-ups: What is the difference between a required named parameter and an optional positional parameter?;Can a single function mix both named and positional parameters together?