Python Named Parameters & the required Keyword
Named parameters (`{Type param = default}`) enclosed in curly braces are the cornerstone of Flutter widget APIs and idiomatic Dart code. Unlike positional arguments where order matters, named parameters are labeled at the callsite (`createUser(name: "Alice", age: 30)`), can appear in any order, and use the `required` keyword for mandatory arguments.
"Named parameters are like filling out labeled form fields on a tax form: it doesn't matter which box you fill first as long as each box is clearly labeled with its name."
Deep Dive: How It Works
Self-Documenting Calls: Callsites like `Button(label: "Submit", isPrimary: true)` make intent unmistakable.
`required` Keyword: Enforces at compile-time that the caller must supply the argument.
Default Values: Optional named parameters can provide defaults (`{int timeoutMs = 5000}`).
Syntax Blueprint
void configure({
required String host,
int port = 8080,
bool enableTls = true,
}) {
print("$host:$port (TLS: $enableTls)");
}Named parameter signature with required and default parameter options.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Declaring a non-nullable named parameter without `required` or a default value.Why it happens: Non-nullable types cannot be null if the caller omits them.
How to fix: Either add `required`, provide a default (`int count = 1`), or make the type nullable (`int? count`).
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Define Function with Named Parameters
Define `void registerUser({required String username, String role = "MEMBER", bool isActive = true})`.
Have it print `User: $username [$role] (Active: $isActive)`.
Call it from `main()` with `username: "dev_alex"`.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.