0Pricing
Dart Academy · Lesson

Arrow Syntax for One-Line Functions

Shorten functions with the fat arrow.

Arrow Syntax for One-Line Functions is a free Dart Academy lesson on CoddyKit — lesson 1 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.

Why Shorten Functions?

Many Dart functions just return one expression. The arrow syntax lets you write those in a single tidy line. ✨

The Fat Arrow

The => symbol, called the fat arrow, replaces the curly braces and the return keyword for one-expression bodies.

From Block to Arrow

This block function returns a sum. Notice how much fits on one line once you reach for the arrow form next.

int add(int a, int b) {
  return a + b;
}

The Arrow Version

Same function, far less noise. The => a + b part is automatically returned for you.

int add(int a, int b) => a + b;

Return Is Implicit

With an arrow there is no return keyword. Whatever the expression evaluates to becomes the function's result.

String greet(String name) => 'Hi, ' + name;

One Expression Only

The arrow body must be a single expression, not several statements. If you need many lines, keep the curly braces.

No Semicolon Inside

You do not put a semicolon before the arrow. The one and only semicolon goes at the very end of the line.

double half(double x) => x / 2;

Arrows Take Any Args

Arrow functions accept the same parameters as block functions: zero, one, or many. Only the body shrinks.

int square(int n) => n * n;

Void and Side Effects

An arrow can call a function too. Here it just prints, so its result is discarded rather than returned.

void shout(String s) => print(s.toUpperCase());

Great for Tiny Helpers

Short utilities like checks and getters read beautifully as arrows. Less ceremony means your intent stands out.

bool isEven(int n) => n % 2 == 0;

Know When to Stop

Resist cramming logic into one expression. If readability drops, a normal block body is the better choice.

Quick Check

Which statement about the fat arrow is true?

Recap

You learned the fat arrow: it turns one-expression functions into clean single lines, implicitly returning the result. 🎯

Frequently asked questions

Is the “Arrow Syntax for One-Line Functions” lesson free?

Yes — the full text of “Arrow Syntax for One-Line Functions” 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 “Arrow Syntax for One-Line Functions”?

Shorten functions with the fat arrow. 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 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Arrow Syntax for One-Line Functions” 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

  1. Arrow Syntax for One-Line Functions
  2. Anonymous Functions and Closures
  3. Nullable Types and the Question Mark
  4. Null-Aware Operators: ?., ??, and !
← Back to Dart Academy