Positional vs Named Parameters
Call functions with clear, ordered or labeled args.
Positional vs Named Parameters is a free Dart Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Dart Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Two Ways to Pass Args
Dart offers two parameter styles: positional and named. Picking the right one makes your function calls clearer and harder to misuse.
Positional Parameters
Positional parameters are matched by order. The first value fills the first slot, the second fills the second, and so on.
int sub(int a, int b) {
return a - b;
}
sub(10, 3); // 7Order Really Matters
With positional args, swapping the order changes the meaning. Here order decides which value is which, so be careful.
sub(3, 10); // -7, not 7Named Parameters
Wrap parameters in braces to make them named. Callers then pass them by label, so the order no longer matters at all.
void move({int x, int y}) {
// ...
}Calling With Labels
When calling a named-parameter function, you write each label followed by a colon. This makes the call read like plain English.
move(y: 5, x: 2);Named Args Are Self-Documenting
Labels turn cryptic calls into readable ones. A reader instantly sees what each value means, making named args great for clarity. 📖
drawBox(width: 100, height: 50);Named Are Optional by Default
Plain named parameters are optional, so callers may skip them. Dart fills skipped values with null unless you say otherwise.
void config({String? theme}) {}
config(); // theme is nullOptional Positional Parameters
Square brackets make positional parameters optional too. Trailing ones can be left off, and they default to null.
String tag(String name, [String? id]) {
return id == null ? name : "$name#$id";
}Mixing Both Styles
You can lead with required positional parameters, then add named ones in braces. Required values come first, the rest stay flexible.
void log(String msg, {bool loud = false}) {}When to Pick Each
Use positional for one or two obvious inputs. Reach for named parameters when a call has many values or booleans that need labels.
Avoiding Boolean Traps
A bare true in a call tells the reader nothing. A named parameter like animate: true makes the intent crystal clear. ✅
show(animate: true);Quick Check
Time to check your grasp of parameter styles.
Recap
You can now choose positional for short calls and named for readable ones, and even mix them. Clear calls mean fewer bugs. 🎯
Frequently asked questions
Is the “Positional vs Named Parameters” lesson free?
Yes — the full text of “Positional vs Named Parameters” is free to read here on the web, and the Dart Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Dart Academy course, upgrade to CoddyKit PRO.
What will I learn in “Positional vs Named Parameters”?
Call functions with clear, ordered or labeled args. You practise Dart Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Dart Academy?
No prior experience is required. Dart Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Positional vs Named Parameters” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Dart Academy lesson?
Yes. Every Dart Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Declaring Functions and Return Types
- Positional vs Named Parameters
- Default Values and required
- Functions as First-Class Values