How to create an async callback in Flutter/Dart?
4,143
Solution 1
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.
Solution 2
Flutter has an async version of the VoidCallback
typedef
, namely AsyncCallback
. See: https://api.flutter.dev/flutter/foundation/AsyncCallback.html
Author by
David
Updated on December 11, 2022Comments
-
David over 1 year
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 likeCallback<Future>
.