Difference between writing platform specific code vs dart:ffi code
Asked Answered
S

1

9

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

Scott answered 19/5, 2020 at 19:49 Comment(0)
M
4

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.

Mutt answered 19/5, 2020 at 23:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.