0

E.g. in Typescript I'd have:

function foo(callback: (num) => string) {
  console.log(callback(1));
}

And even in C/C++ you can do it using an insane syntax:

void foo(string (*callback)(int)) {
  cout << callback(5) << "\n";
}

How do I do the same in Dart without resorting to typedef?

Timmmm
  • 88,195
  • 71
  • 364
  • 509
  • Does this answer your question? [Pass a typed function as a parameter in Dart](https://stackoverflow.com/questions/43334714/pass-a-typed-function-as-a-parameter-in-dart) – Mattia Dec 22 '19 at 17:43

1 Answers1

0

You can declare the function return type, and parameters in a way similar to when you define a function:

void foo(String callback(int n)) {
  print(callback(1));
}

Mattia
  • 5,909
  • 3
  • 26
  • 41