11

I'm trying to add an async callback to a model in a flutter application so the model can give the view an opportunity to show some dialog before the model continues on. However, I can't seem to find an async callback. I see VoidedCallback but I don't see anything like Callback<Future>.

3 Answers 3

20

Flutter has an async version of the VoidCallback typedef, namely AsyncCallback. See: https://api.flutter.dev/flutter/foundation/AsyncCallback.html

Sign up to request clarification or add additional context in comments.

Comments

8

The VoidCallback is just a signature for method callback without parameters.

typedef VoidCallback = void Function();

You can create your own:

typedef FutureCallback = void Function(Future);

Or you can just use the final Function(Function) foo = yourcallback directly.

3 Comments

Thanks! This worked for me: typedef FutureCallback = Future Function();
can you tell in details how to use the solution ?
I think in the above mentioned example, the async version of VoidCallback should be typedef FutureCallback = Future<void> Function();, not void Function(Future).
2

This is how you define an async callback function in Dart:

typedef FutureCallback = Future<void> Function();

Example:

FutureCallback myFunction;

await myfunction.call();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.