Difference between writing platform specific code vs dart:ffi code

525

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.

Share:
525
Pratik Mohite
Author by

Pratik Mohite

Working with visual world.

Updated on December 20, 2022

Comments

  • Pratik Mohite
    Pratik Mohite over 1 year

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