Python Functions, Return Types & Arrow Syntax (=>)
Functions in Dart are first-class objects, meaning they can be assigned to variables, passed as arguments, and returned from other functions. Functions specify explicit return types (`int`, `String`, `void`), and single-expression functions can be written concisely using fat arrow syntax (`=> expr`), returning the evaluated expression automatically.
"A function is like a kitchen blender: you put specific ingredients into the top (parameters), run the blending cycle, and pour out the smooth result (return value)."
Deep Dive: How It Works
First-Class Citizens: Functions can be stored in variables (`final fn = print;`) or passed into collection methods.
Arrow Syntax (`=>`): Shorthand for `{ return expr; }`. Only a single expression is allowed after `=>`.
Return Type Invariance: Omitting return types falls back to `dynamic`, so always annotate explicit return types (`void`, `bool`, `int`).
Syntax Blueprint
// Standard block function
int add(int a, int b) {
return a + b;
}
// Arrow syntax function
int multiply(int a, int b) => a * b;Block body with return statement vs single-expression arrow function.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Putting statements (like `if` statements or loops) after an arrow `=>`.Why it happens: `=>` expects an expression that yields a value, not control flow statements.
How to fix: Use a standard block `{ ... }` if you need multi-line statements, or use a ternary expression with `=>`.
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.
Write an Arrow Function
Define an arrow function `double calculateTax(double subtotal, double rate) => subtotal * rate;`.
Inside `main()`, call `calculateTax(100.0, 0.08)` and print `Tax: $tax`.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.