3

I'm developing a flutter application that has some native codes, that is, I use the channel to retrieve some native resources, so far my application works fine, but when using libs to have a floating window in any part of the system I need to use the vm-entry-point to instantiate these windows.

Example:

@pragma("vm:prefer-inline")
void overlayMain() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(
    const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MessangerChatHead(),
    ),
  );
}

By doing this I manage to make a floating window in the app, but inside the dart messagerchatheader class, it cannot find my application channel, and in other parts of the app without being a vm-entry-point I can normally call functions that are in the part Native, has anyone had this problem?

From the little I researched, I saw that the vm-entry-point is used to be called from the native side, that is, Kotlin calls flutter, and maybe that's why it doesn't find the flutter channel that I use in the rest of my application.

The function I use to call the native part is this:

static Future<double> getCpuLoadPerCore(int core) async {
  try {
    double result = await platform.invokeMethod("cpuLoadPerCore", {"coreNumber": core});

    return double.parse(result.toStringAsFixed(2));
  } on PlatformException catch (e) {
    return Future.value(0);
  }
}
double-beep
  • 5,031
  • 17
  • 33
  • 41
  • Hi @Rogers Marques Did you find out any solution to this? I am facing same issue at my end. – Shriya Pandya Mar 02 '23 at 06:15
  • @ShriyaPandya I still have the same problem, the temporary solution I found was instead of using the popup library, I studied the library and implemented a native implementation in my own application, and there, in its channel, I implemented the methods I needed to call; – Rogers Marques Mar 03 '23 at 14:50
  • Thanks for replying. I am facing issue while fetching data from android , inside flutter background serve call. I even have wrote a question about it. Can you have a look? https://stackoverflow.com/questions/75654445/methodchannel-is-not-calling-from-background-service-onstart-in-flutter – Shriya Pandya Mar 06 '23 at 18:23
  • One way to solve this Channel communication problem that I recently discovered is the following, as I needed a floating window I used flutter_overlay_window And I created a plugin that has the channels I need, I made async functions for what I need, I can use it in the normal context of the app and in the context of @progma, because as it is a plugin it has its execution isolated – Rogers Marques Jul 01 '23 at 20:44

0 Answers0