Arrow functions

on Saturday, 25th of July, 2020

Dart also supports a nice shorthand syntax for any function that has only one expression. In other words, is the code inside the function block only one line? Then it's probably a single expression, and you can use this syntax to be concise:

String makeGreeting(String name) => 'Hello, $name!';

main() {

For lack of better term, we'll call this an arrow function. Arrow functions implicitly return the result of the expression. => expression; is essentially the same as { return expression; }. There's no need to (and you can't) include the return keyword.

Join thousands of Flutter developers.

Sign up for infrequent updates about Flutter and Dart.

You can get all this content and more in one place. Check out my new book Flutter in Action