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() {
print(makeGreeting('Wallace'));
}
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.