Posted on :: Tags: , , ,

Sometimes we need anonymous functions for one-off tasks. Dart allows two similar syntaxes for writing these.

The first one is used when there is a single expression to write:

(a, b) => a + b

The other is used when you need to write multiple statements in an anonymous function:

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