Dart => expr syntax notes:
Only an expression—not a statement—can appear between the arrow (=>) and the semicolon (;).
case:
sayHello(String name) => print("Hello, $name");
Here I think print is a statement.
Generally we agree:
=> can be understood as a single-line function, a expression or a single-line statement(Function Expression).
if ..., for ..., switch ..., would be statements. print() is a function call that evaluates to void and is an expression as a + b which is also a function call like a.operator+(b) just with a different syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With