Since dart:ffi is available from Dart 2.2.0-dev.2.0
, I've been trying to use that library. The sample app works fine for me and I also tried to use it for my Flutter app but I couldn't call it with import "dart:ffi"
, although Flutter on my machine was HEAD
of master
that used Dart 2.3.0-dev.0.0
.
I checked what happened, then I found that sky_engine didn't contain ffi.dart
while it contained other libraries (e.g. "dart:core"). Also I noticed that the source files of those libraries were copied from $FLUTTER_ROOT/bin/cache/dart-sdk/lib
to $FLUTTER_ROOT/bin/cache/pkg/sky_engine
using BUILD.gn or _embedder.yaml and that seemed to be why I couldn't use the dart:ffi
in my Flutter app.
However, in the first place, why does Flutter need sky_engine, which is "the interface between Dart and the Flutter Engine"? Why not calling them directly without this glue code?
Flutter has a good documentation for FFI to be able to call native C APIs. Adding import 'dart:ffi' as ffi;
on the Flutter app works without issues as of my testing with Flutter 2.5. If you're able to provide a minimal repro of your issue, this will help folks to understand the question better.
As for the question on why sky_engine is used by Flutter, that's just simply because it's the "flutter_engine" - similar to what has been already mentioned in the comments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With