Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an async callback in Flutter/Dart?

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>.

like image 254
David Avatar asked Mar 21 '26 01:03

David


2 Answers

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

like image 91
JJuice Avatar answered Mar 23 '26 13:03

JJuice


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.

like image 41
Miguel Ruivo Avatar answered Mar 23 '26 13:03

Miguel Ruivo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!