0

i'm developing android/ios app with flutter. Even if you use flutter, there are many cases where you have to use native code. I found a way to call native code in flutter by referring to the official flutter documentation. That's 'MethodChannel'.

However, there is a situation where you need to use C code. I did a search and it said dart/ffi exists. I did not use it and solved it by calling it from native code.

The problem is that I don't know how to call the flutter function in C. I've searched, but all of them only provide a way to call from flutter.

Example

//flutter Function
Future<Widget> drawHorizonLine(double posX, double posY, double len){
   return Positioned(
      top: posY,
      left: posX,
      child: drawHorizonLine(double len);
   );
}

////////////////////////////////////////

//C Code
bool drawLine(){
  
 //implements
 ...
 //call Flutter Function
 drawHorizonLine(100, 100, 300); //draw HorizenLine
 drawHorizonLine(100, 120, 300); //draw HorizenLine
 drawHorizonLine(100, 140, 300); //draw HorizenLine
 ...
 return true;
}

I would like to know how to call a flutter function from C code like an example. thank you

The duplicate question is an example of calling back to C when calling C from dart. I want to know how to call dart function directly from C.

Jungwon
  • 1,038
  • 7
  • 20
  • BTW, there's no way to call from C to Dart into a Dart method that returns `Future`. The Dart method must return immediately. – Richard Heap Oct 19 '22 at 13:01

0 Answers0