Can I pass a setter (not the value) as parameter to a function without reflection?

You can't directly pass the setter.

To avoid reflection you can wrap the setter inside a function :

class A {
  String _attr=;
  set attr(String v) => _attr = v;
}

main() {
  final a = new A();

  // create a wrapper function to set attr
  final setter = (v) => a.attr = v;

  callSetter(setter);
  print(a._attr);
}

callSetter(setterFunction(value)) {
  setterFunction("value");
}

This proposal about generalized tear offs is approved and will probably implemented soon and allows to closurize getters and setters like:

var setter = a#attr;
// and can be invoked like
setter(value)

Tags:

Dart