Bottom line

  • “Lambda” = anonymous function
  • “closure” = function with its environment.
  • In Dart, lambdas are closures, but the terms aren’t synonymous

Lambda

  • An anonymous function literal, e.g., () { ... } or () => expr.
  • It’s about syntax (no name).

Closure

  • A function object that carries its lexical environment (captures variables from surrounding scope).
  • It’s about behavior.

In Dart

  • All functions are closures (including top-level, static, named, lambdas, and method tear-offs), but “closure” emphasizes that the function can access surrounding variables.
  • A lambda may or may not capture anything. If it captures, it’s a capturing closure; if not, it’s a zero-capture closure.

Example

Capturing closure (lambda)

  • Returns a function that closes over count:
VoidCallback makeCounter() {
  var count = 0;
  return () { count++; print(count); };
}

Non-capturing lambda

onTap: () => print('hi');

Method tear-off

  • (also a closure, often preferable to avoid wrapping):
onTap: widget.onComplete