I have a custom flutter plugin. From Flutter app I call the setMethodCallHandler on the channel which I use to invoke method on native. Flutter to native communication works along with the responses. But the reverse is not working, where the methods are invoked on native side. The native tries to call the methods but it is not able to find the callbacks as the response is always "not implemented"
The channel is defined in the Flutter plugin and I set the methodHandler during the initialization of app.
VpvpBaseModulePlugin.dart
static const platformNative = const MethodChannel('com.example.test/native_channel');
static void setMethodCallHandler(Future<dynamic> handler(MethodCall call)){
channel.setMethodCallHandler(handler);
}
Flutter app
Future<dynamic> handler(MethodCall methodCall) async {
switch (methodCall.method) {
case 'callMe':
print("***** callMe: ${methodCall.arguments}");
break;
}
}
VpvpBaseModulePlugin.setMethodCallHandler(handler);
Native Call:
public lateinit var channel : MethodChannel
class VpvpBaseModulePlugin: FlutterPlugin, MethodCallHandler{
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
flutterEngine = flutterPluginBinding.flutterEngine
channel = MethodChannel(flutterPluginBinding.getFlutterEngine().getDartExecutor(), "com.example.test/native_channel")
channel.setMethodCallHandler(this)
context = flutterPluginBinding.applicationContext
}
}
Handler(Looper.getMainLooper()).post {
val arguments = HashMap<String, Any>()
arguments["errorCode"] = error.toString();
channel.invokeMethod("callMe", arguments)
}
the invocation of calls from flutter app's native module works.. but they are not working from plugin's native