flutter.wtf
648 subscribers
53 photos
45 videos
60 links
πŸš€ Leading Flutter development agency. About us: https://flutter.wtf/about.
Download Telegram
​​#ffi #integration

Foreign Function Interface πŸ”₯

For C-based APIs, including those that can be generated for code written in modern languages like Rust or Go, Dart provides a direct mechanism for binding to native code using the dart:ffi library.

The foreign function interface (FFI) model can be considerably faster than platform channels, because no serialization is required to pass data. Instead, the Dart runtime provides the ability to allocate memory on the heap that is backed by a Dart object and make calls to statically or dynamically linked libraries. FFI is available for all platforms other than web, where the js pachage serves an equivalent purpose.

To use FFI, you create a typedef for each of the Dart and unmanaged method signatures, and instruct the Dart VM to map between them. As a simple example, here’s a fragment of code to call the traditional Win32 MessageBox() API: