Power Tools: Arrow Syntax & List Methods
9 min · Dart
Skip the curly braces with arrow functions, and transform lists with map and where.
Enemy 1 of 5
Arrow syntax for one-line functions
When a function's entire body is just a single expression whose value you want to return, Dart lets you skip the curly braces and return keyword entirely with arrow syntax: => expression is shorthand for { return expression; }. int square(int n) => n * n; behaves identically to writing out the full block form, just more compactly.
Arrow syntax works anywhere a function body would normally go — top-level functions, methods on a class, and the anonymous functions you pass into .map() and .where() below — but it's only valid for a single expression. The moment your logic needs more than one statement (like an if or a loop), you need to switch back to the full { } block form.
Loading editor...