dart-archive/ffi

How to share progress updates through FFI?

perojas3 opened this issue · 6 comments

Basically this question but for Dart: https://stackoverflow.com/questions/15768748/how-to-share-progress-updates-through-jni
I have a C library that can report progress, and want to get those reports in dart, preferably in a stream.
Right now, in Andorid/Flutter I'm using platform channels between Dart to Kotlin, and JNI between Kotlin and C.
But I wish to remove the use of Kotlin code if possible, and would allow me to port to desktop in the future.
Any way to do this in FFI?

You would need to use asynchronous callback. dart:ffi does not support that yet out of the box, but there is a way to do it with native ports. See the documentation in dart-lang/sdk#37022.

Ok.
One more thing, there is anyway to cancel?
Specifically, from the UI have a cancel button, to stop in C.
I have a flag in C that is checked, if is true, free all the memory and stops the process.

Yes, just do an FFI call to C that sets that flag.

You would need to use asynchronous callback. dart:ffi does not support that yet out of the box, but there is a way to do it with native ports. See the documentation in dart-lang/sdk#37022.

Is there any plan for support it out the box in dart:ffi ? Thank you!

Is there any plan for support it out the box in dart:ffi ? Thank you!

Yes, but I cannot comment on a timeline for any of the open issues.

Work is tracked in the bug mentioned above.