How can I create the type from existed function in Dart/Flutter?
I know typedef
can create custom type, something like:
typedef Custom<T> = int Function(T a, T b)
But if I have a function from the dependency and want to create the type for arguments, how can I do this?
int functionFromDependency(String a, {int b, ComplexType c}) {
// ...
}
// something syntax like `typeof<functionFromDependency>`
void myProcess(typeof<functionFromDependency>? runner) {
(runner ?? functionFromDependency)(
a,
b: b,
c: c
);
}
It is helpful for testing which can inject custom function.
myProcess
function already depends on the actual type ofrunner
when passing arguments.myProcess
needs to take a function with a specific signature, and callers need to conform tomyProcess
's API, not the other way around.