Questions tagged [dart-ffi]

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).

109 questions
4
votes
0 answers

Is there a way to send a dart array to C without copying the array?

I am using dart:ffi. I have a C function that accepts a pointer to array: void myCFunc(const void *pointer); I want to call it from dart, right now, I am calling it like this: void myDartFunc(Uint8List data) { final Pointer dataPtr…
HII
  • 3,420
  • 1
  • 14
  • 35
4
votes
1 answer

Dart FFI keep Struct pointer

I am trying to call a C library from dart. The C code as a genertor method such as a_struc create_struct(void); and then methods that take in a pointer to struct, such as: const char * get_info(const a_struc * s); I have created the dart binding…
Malcolm
  • 662
  • 7
  • 29
4
votes
1 answer

Dart ffi - Call Dart From C++

I am making a flutter application where I have my backend as C++. Through dart ffi I am signalling a load call when user enters a certain screen. My problem is Im loading audio in C++ but I want to signal dart that the loading has finished so that I…
cs guy
  • 926
  • 2
  • 13
  • 33
4
votes
2 answers

Debug C++ code from Dart package using dart::ffi

I am developing a package in C++ to be used in a Flutter app (and therefore in Dart), using dart::ffi and I was wondering if there was a better way to debug (step by step, variable watch, that sort of things) the C++ code, other than logging…
Facundo Farall
  • 500
  • 6
  • 18
4
votes
1 answer

Whats the difference between writing MethodChannel bridge versus dart:ffi bridge to run c/c++ code to get the response?

Before I start my question I want to point out that it's not similar this question. Difference between writing platform specific code vs dart:ffi code. Here the questioner is asking the actual difference whereas I am trying to know the difference…
Aawaz Gyawali
  • 3,244
  • 5
  • 28
  • 48
3
votes
1 answer

How to convert RGB pixmap to ui.Image in Dart?

Currently I have a Uint8List, formatted like [R,G,B,R,G,B,...] for all the pixels of the image. And of course I have its width and height. I found decodeImageFromPixels while searching but it only takes RGBA/BGRA format. I converted my pixmap from…
itzMeerkat
  • 33
  • 5
3
votes
1 answer

Convert Dart String to dartffi Pointer

I used ffigen to generate bindings from a C header file. One of the methods in C is open(const char *path), and ffigen generated a binding method open(ffi.Pointer path). If I want to have a dart method open(String path) that access this…
J. Gatica
  • 153
  • 1
  • 10
3
votes
2 answers

How to include dlls in flutter build windows

I am working on a flutter project that runs fine in development. However I do not know how to get the build to include dll's referenced using FFI. I can't find clear instructions on how to do it. I tried following the steps to build an msix here,…
xerotolerant
  • 1,955
  • 4
  • 21
  • 39
3
votes
1 answer

How can I load a C dynamic library for FFI by specifying path in flutter?

I want to load a C Dynamic Library in flutter, how can I specify the path, and open it? is it possible to add .so file to the asset folder? final dynamicLibrary = DynamicLibrary.open(libraryPath); final Pointer Function() _someMethod =…
Hamed
  • 5,867
  • 4
  • 32
  • 56
3
votes
1 answer

What is 'Native Type' for 'char*' in dart FFI?

I have a function like this in C language: char* getString() { return "SOME_STRING"; } now I want to invoke it by FFI in dart, and this is my code: import 'dart:io'; import 'dart:ffi'; void main(List arguments) { …
Hamed
  • 5,867
  • 4
  • 32
  • 56
3
votes
1 answer

Testing Library functions in a flutter package with Native Functions using Dart::ffi

I am writing a Dart library to access a C shared object using Flutter. So far, the example app I created is working (somewhat) as expected, but i want to include Unit testing too keep the library somewhat stable. Details: Shared Objects are in…
Ryan Deschamps
  • 351
  • 4
  • 16
3
votes
0 answers

How to convert C++ cv::Mat to Flutter variable?

I'm very new to flutter. I'm trying to send an image from my OpenCV-C++ code to flutter for iOS device through dart:ffi. I first converted cv::Mat to vector. I'm not sure if this is a right approach. Still, I'm stuck at how to define lookup…
fai
  • 31
  • 1
3
votes
2 answers

Can I call a C++ constructor function in dart ffi?

I'm new to ffi. But I successfully used dart-ffi with functions call. Now, I'd like to use a C++ object in dart ffi. I don't know if it is possible, but I tried like this. The prototypes of constructor call are : function_dart = lib …
XavierB
  • 2,198
  • 1
  • 9
  • 12
3
votes
1 answer

Casting an int to Uint8 in Dart

I am using the ffi and tyed_data Dart libraries and keep running into an error with this line of code, Uint8 START_OF_HEADER = 1 as Uint8; My error: type 'int' is not a subtype of type 'Uint8' in type cast What am I doing wrong here? Another…
temp_
  • 1,238
  • 2
  • 12
  • 24
2
votes
1 answer

Processing flutter images with C++ openCV

I am working on a project, where I want to process my images using C++ OpenCV. For simplicity's sake, I just want to convert Uint8List to cv::Mat and back. Following this tutorial, I managed to make a pipeline that doesn't crash the app.…
Oleksandr Firsov
  • 1,428
  • 1
  • 21
  • 48