Difference between writing platform specific code vs dart:ffi code

青春壹個敷衍的年華 提交于 2020-06-15 04:10:50

问题


What is difference between writing code using dart:ffi in flutter or writing code with the method chanel in flutter.


回答1:


dart:ffi is used to call C/C++ code - typically to reuse an existing C/C++ library - often a CPU intensive operation, like codecs, image processing, cryptography. The C code has limited access to the system APIs.

Method channels are used to access the underlying environment and its APIs - so are written in Kotlin or Java on Android, Swift or Objective C on iOS and macOS and Dart in Flutter Web.

So, for example, if you want to read the battery level of the device, you need to use a method channel and implement the native API call in its native language, e.g. Java for Android. Conversely, if you want to call a C library that implements a cryptographic hash, the easiest way is to use ffi.

Check out the Flutter Week videos for a novel use of ffi to call the Android NDK / Oboe audio library.



来源:https://stackoverflow.com/questions/61899563/difference-between-writing-platform-specific-code-vs-dartffi-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!