Use this tag for questions about Dart's Foreign Function Interface (FFI) - the ability to call C directly from Dart. It is equally applicable to applications running in the Dart VM and to Flutter applications (except Flutter Web, of course).
Questions tagged [dart-ffi]
109 questions
                    
                    21
                    
            votes
                
                10 answers
            
        mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64') in Flutter
Executing dart run ffigen got the following error:
Unhandled exception:
Invalid argument(s): Failed to load dynamic library '/Users/bruce/homebrew/opt/llvm/lib/libclang.dylib': dlopen(/Users/bruce/homebrew/opt/llvm/lib/libclang.dylib, 0x0001):…
        
        arcticfox
        
- 239
 - 1
 - 2
 - 5
 
                    14
                    
            votes
                
                1 answer
            
        Dart/Flutter ffi (Foreign Function Interface) native callbacks eg: sqlite3_exec
Hello I am using dart:ffi to build an interface with my native c/c++ library.
and I needed a way to get a callback from c to dart as an example in sqlite:
int sqlite3_exec(
    sqlite3*,                                  /* An open database */
   …
        
        Ala'a Al Hallaq
        
- 455
 - 5
 - 11
 
                    9
                    
            votes
                
                1 answer
            
        C++ call Dart function in Flutter
Flutter can binding to native code using dart:ffi. In other words, Dart can call C ++ methods, but can C ++ call Dart methods?
as follows:
        
        Liu Silong
        
- 4,902
 - 3
 - 19
 - 28
 
                    8
                    
            votes
                
                1 answer
            
        How to map Dart String with FFI
I've the Dart type as:
typedef dart_func = String Function(String x);
And want to map it with Dart FFi, but their could not find neither String, nor Utf8, I tried
typedef ffi_func = ffi.Pointer Function(ffi.Pointer x);
But it failed,…  
        
        Hasan A Yousef
        
- 22,789
 - 24
 - 132
 - 203
 
                    7
                    
            votes
                
                1 answer
            
        Flutter C++ Memory allocation causes jank on raster thread - Android NDK Dart FFI
I have a flutter app which uses Dart ffi to connect to my custom C++ audio backend. There I allocate around 10MB of total memory for my audio buffers. Each buffer has 10MB / 84 of memory. I use 84 audio players. Here is the ffi flow:
C++…
        
        cs guy
        
- 926
 - 2
 - 13
 - 33
 
                    7
                    
            votes
                
                2 answers
            
        flutter/dart: How to use async callback with Dart FFI?
My app's backend is written in C++ and the frontend in Dart/flutter.
I'd love to have the backend notify frontend whenever data is ready.
This requires implementing an async callback scheme between Dart and C++.
Environment
$ flutter doctor -v
[✓]…
        
        kakyo
        
- 10,460
 - 14
 - 76
 - 140
 
                    7
                    
            votes
                
                1 answer
            
        Difference between writing platform specific code vs dart:ffi code
What is difference between writing code using dart:ffi in flutter or writing code with the method chanel in flutter.
        
        Pratik Mohite
        
- 95
 - 1
 - 8
 
                    7
                    
            votes
                
                0 answers
            
        Flutter dart:ffi use static c library .a archive
The documentation is very unclear about how to use a static library that is provided through an archive file (library.a)
First-party library A first-party native library can be included
  either as source or as a (signed) .framework file. It’s…
        
        Daniel Eberl
        
- 1,268
 - 1
 - 10
 - 22
 
                    7
                    
            votes
                
                1 answer
            
        How do I Print to Console using dart:ffi in Flutter?
Trying to print to console when running my Flutter app (on Android) from the following C++ code I am running through dart:ffi:
#include 
std::cout << "Hello, World!";
Does not give me any output in the terminal. How would I print to the… 
        
        creativecreatorormaybenot
        
- 114,516
 - 58
 - 291
 - 402
 
                    6
                    
            votes
                
                1 answer
            
        How to convert Uint8List to C equivalent datatype using dart:ffi
I am trying to send an image to my Custom C++ code which I am planning to run using dart:ffi. I have successfully run the hello world problem where I send two integers and get the some of them as another intiger. 
Now I want to send a whole image to…
        
        Aawaz Gyawali
        
- 3,244
 - 5
 - 28
 - 48
 
                    5
                    
            votes
                
                7 answers
            
        Error: Not found: 'dart:ffi' with flutter web
Read carefully before reporting.
My flutter web project was working perfectly fine. A few hours later, it started complaining about 'dart:ffi: which i didn't even import. I saw similar questions but none of them were in my case. I tried everything I…
        
        Mamoudou Kane
        
- 141
 - 2
 - 7
 
                    5
                    
            votes
                
                1 answer
            
        type safe memory allocation with dart ffi
I'm trying to make my code a little more robust when allocating memory for ffi.
I've written the following function:
void withMemory(
    int size, void Function(Pointer memory) action) {
  final memory =…  
        
        Brett Sutton
        
- 3,900
 - 2
 - 28
 - 53
 
                    5
                    
            votes
                
                1 answer
            
        Using AssetManager class from Android NDK in a Flutter app
I've been trying to use the Android NDK's AssetManager class in my Flutter app, that works with Google Oboe, to access to audio files. Following this example in the Oboe repository, I learned that they obtain the AssetManager from Java like…
        
        Facundo Farall
        
- 500
 - 6
 - 18
 
                    5
                    
            votes
                
                2 answers
            
        How to pass native void pointers to a Dart Isolate - without copying?
I am working on exposing an audio library (C library) for Dart. To trigger the audio engine, it requires a few initializations steps (non blocking for UI), then audio processing is triggered with a perform function, which is blocking (audio…
        
        Philiste
        
- 161
 - 13
 
                    5
                    
            votes
                
                1 answer
            
        Dart C Interoperability. Pass an array of integers to C function
I am learning Dart now and I playing with Dart's Interoperability with C. I am able to use a C method with two int params. Code below:
hello.dart
import 'dart:ffi' as ffi;
typedef sum_func = ffi.Int32 Function(ffi.Int32 a, ffi.Int32 b);
typedef Sum…
        
        Dan Cantir
        
- 2,915
 - 14
 - 24