Reputation: 2822
So In my class constructor I want to accept a function as input so:
class foo() {
final Function inpFunc;
foo({this.inpFunc});
}
I want to only accept functions that return int but final Function<int> inpFunc
is not valid
What should I do?
Upvotes: 15
Views: 11438
Reputation: 6161
You can add return type and parameter details to be more specific.
int Function()
for instance.
class Foo {
final int Function() inpFunc;
Foo(this.inpFunc);
}
main() {
var foo = Foo(() => 42);
print(foo.inpFunc());
}
Upvotes: 30