flutterdart

In Dart, how to pass a function as parameter that returns a Future


I'm trying to pass a function that returns Future<Response> as parameter of a method

I tried to do

Future<String> _execute(Function<Future<Response>>() function) async { }

but it does not even compile.

What's the correct syntax?


Solution

  • You can do it like this,

    Future<String> _myFunction(Future<Response> Function() function) {
      ...
    }