I am developing an application in Flutter (for Android) whose core is based on a library developed only in C++ and python. Therefore, I would like to know how I can use this library in my dart code (either the C++ version or the Python version).
-
3can you give some sample code (both Dart and C++), otherwise @Xavier answer seem to be the one. – TruongSinh Mar 02 '19 at 10:43
-
4Try this [video](https://www.youtube.com/watch?v=X8JD8hHkBMc) by Richard Heap, it helped me quiet a lot. He explains with an example how to interact between the Dart code of your Flutter app, and the C++ library you're using, all through ```dart:ffi```. I'd also recommend checking out this [post](https://stackoverflow.com/questions/62351258/debug-c-code-from-dart-package-using-dartffi) for a way to debug the C++ code while running it through a Flutter app. – Facundo Farall Jun 18 '20 at 18:29
1 Answers
Additional information (2021-05-05)
From @FacundoFarall comment to the original question:
Try this video by Richard Heap, it helped me quiet a lot. He explains with an example how to interact between the Dart code of your Flutter app, and the C++ library you're using, all through dart:ffi. I'd also recommend checking out this post for a way to debug the C++ code while running it through a Flutter app.
Update (2019-09-10)
Today has been released Dart 2.5 (and Flutter 1.9). One of the additions to Dart 2.5 is "the dart:ffi foreign function interface for calling C code directly from Dart." I still haven't checked it, but it should provide a more direct path to interface with C (and C++) code.
See also the announcement video (confirms both old and new methods).
Old answer (still valid)
I would take a look at Platform Channels, which are a way to communicate Flutter code to platform native code (e.g. Java/Kotlin on Android, Objective C/Swift in iOS). From there, you can use your C++ library using the regular NDK mechanisms.
You can see an introduction to Flutter Platform Channels and Getting Started with the NDK.
Maybe there's a more direct route, but that's the one I know could work.

- 6,388
- 1
- 27
- 50
-
1i checked first answer and it's ok with dart compiler but i could not use it in flutter, i raised a question for it https://stackoverflow.com/q/57900637/2719243 – Vahab Ghadiri Sep 12 '19 at 06:35
-
3