opencv_dart icon indicating copy to clipboard operation
opencv_dart copied to clipboard

Remove the dependency of Flutter

Open rainyl opened this issue 1 year ago • 3 comments

Actually, Flutter is NOT necessary for this package, it was included just because Flutter is required for dlls to be correctly included for a flutter app, similar to onnxruntime

Native Assets is a better solution, I have tried to use it but without success, I need to customize the build process and use cmake to correctly build opencv and opencv_dart, but the documentations of Native Assets is really insufficient and the feature is not mature.

So, for a pure dart project, it is not suitable to make Flutter as dependency, maybe we should explore more about Native Assets, or another package for pure dart. Or, maybe this is not important, afterall, it seems nearly all of dart users just use it to develop flutter app.

  • https://github.com/dart-lang/pub/issues/3563

rainyl avatar Mar 20 '24 09:03 rainyl

Thanks for your great work! I have been struggling with generating OpenCV Flutter library via FFI until I found your project, which has inspired me a lot.

For this issue, maybe sqlite3.dart, a pure-Dart database package on which drift depends could help you. It separates the implementation of FFI bindings and native libraries, so users can provide their own native libraries. For example, in Flutter, we can use sqlite3.dart to call FFI bindings and sqlite3_flutter_libs package to load native libaries, and in Android the latter uses sqlite-native-libraries which builds sqlite via CMake.

I think it's a great layered design and hope it's helpful to you.

SageMik avatar Apr 15 '24 12:04 SageMik

Thanks for your approval and suggestions.

I used to consider splitting to different packages, just like OpencvSharp, but pub.dev limits the maximum size of packages to 100M, so for some platforms like android, several .so in a package will exceed the limitation, and it will be laborious if I have to publish 4 and even more packages every time a new version is released.

Actually, I have started working on Native Assets https://github.com/dart-lang/sdk/issues/50565, it is not stable enough, but I have managed to make it work for pure dart and flutter on windows, but for android and ios there are still some problems.

Anyway, thanks for your suggestions, but I think Native Assets will be the best solution in the future, although it's not stable enough for now, I decide to work more on it. If you are interested, contributions are welcome!

rainyl avatar Apr 15 '24 14:04 rainyl

Native-Assets build test

~~For now, main channel required~~

~~flutter channel main && flutter upgrade~~

Tested on Flutter 3.19.6 and above

Worked: Windows, Linux, Android For ios: build to app success but not tested on real devices

rainyl avatar Apr 16 '24 03:04 rainyl