You can use the noSuchMethod method for the class (perhaps in combination with the call() method, but I have not tried this). But it seems that you are losing some of the dart editor checking features when using this (at least for me).
A method has an Invocation instance as a parameter that contains the method name and all unnamed parameters as a list and all named parameters as a hash map.
Read more about noSuchMethod and call() here . But the link contains outdated information that is not relevant to Milestone 4, see here for changes.
Something like that:
typedef dynamic FunctionWithArguments(List<dynamic> positionalArguments, Map<Symbol, dynamic> namedArguments); class MyFunction { final FunctionWithArguments function; MyFunction(this.function); dynamic noSuchMethod(Invocation invocation) { if(invocation.isMethod && invocation.memberName == const Symbol('call')) { return function(invocation.positionalArguments, invocation.namedArguments); } return; } }
Using:
class AClass { final aMethod = new MyFunction((p, n) { for(var a in p) { print(a); } }); } var b = new AClass(); b.aMethod(12, 324, 324);
Fox32 source share