Dart ffi – Call Dart From C++

Issue

I am making a flutter application where I have my backend as C++. Through dart ffi I am signalling a load call when user enters a certain screen. My problem is Im loading audio in C++ but I want to signal dart that the loading has finished so that I can stop showing a loading screen. AFAIK, there is no way to call dart from C++. I have seen that you can use FromFunction. Source here.

How can I call a void class method with no parameters? or How can I call dart code from C++?

Ps: I think this is impossible to do this as of now (without work arounds). Dart devs please add this feature as it is very useful to be able to make calls to dart to process information 🙏

Solution

Currently, the only way to make asynchronous callbacks is through the native ports in dart_api_dl.h (and dart_api.h).

Sample code:

For more info see the issue for adding support for async callbacks to dart:ffi.

Answered By – Daco Harkes

Answer Checked By – Senaida (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *