Is it possible to call a native function using MethodChannel from an Isolate? The documentation only shows how to adapt the native code in the case of plugins. However, I'm using MethodChannel as described in the page linked above, without creating a plugin.
Code in Flutter Isolate:
DartPluginRegistrant.ensureInitialized();
const methodChannel = MethodChannel('MethodChannel');
final double result = await methodChannel.invokeMethod('getAltitude');
Code in MainActivity.kt:
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine); // saw this in another thread. Tested with and without it
super.configureFlutterEngine(flutterEngine)
val taskQueue = flutterEngine.dartExecutor.binaryMessenger.makeBackgroundTaskQueue()
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "MethodChannel", StandardMethodCodec.INSTANCE,taskQueue).setMethodCallHandler {
call, result ->
if (call.method == "getAltitude") {
val altitude = "xxx"
result.success(altitude)
} else {
result.notImplemented()
}
}
}
This is the error I get:
MissingPluginException (MissingPluginException(No implementation found for method getAltitude on channel MethodChannel))