handleMethodCall method

Future handleMethodCall(
  1. MethodCall call,
  2. MethodChannel channel
)

Handles method calls over the MethodChannel of this plugin. Note: Check the "federated" architecture for a new way of doing this: https://flutter.dev/go/federated-plugins

Implementation

Future<dynamic> handleMethodCall(
    MethodCall call, MethodChannel channel) async {
  // final MethodChannel channel = MethodChannel('com.wiseminds.mono_flutter', );
  switch (call.method) {
    case 'setup':
      onLoad() {
        // print('MonoFlutterWeb: loaded');
        channel.invokeMethod('onLoad', {});
      }
      onClose() {
        // print('MonoFlutterWeb: onClose: ');
        channel.invokeMethod('onClose', {});
      }
      onEvent(eventName, data) {
        // print(
        //     'MonoFlutterWeb: onEvent: $eventName,${eventName.runtimeType} :${data.runtimeType} $data, ${jsToMap(data)}');
        channel.invokeMethod('onEvent',
            {'eventName': eventName, 'data': jsonEncode(jsToMap(data))});
      }
      onSuccess(data) {
        // print('MonoFlutterWeb: onSuccess:${data.runtimeType} $data');
        channel.invokeMethod('onSuccess', jsonEncode(jsToMap(data)));
      }

      setProperty(html.window, 'onLoad', allowInterop(onLoad));
      setProperty(html.window, 'onClose', allowInterop(onClose));
      setProperty(html.window, 'onEvent', allowInterop(onEvent));
      setProperty(html.window, 'onSuccess', allowInterop(onSuccess));

      setupMonoConnect(
          call.arguments['key'] as String,
          call.arguments['reference'] as String?,
          call.arguments['config'] as String?,
          call.arguments['authCode'] as String?);
      // try {
      //   var authCode =  call.arguments['authCode'] as String?;
      //  if(authCode != null && authCode.isNotEmpty) {
      //    reauthorise(authCode);
      //  }
      // } catch (e) {
      //   print('MonoFlutterWeb: onLoad: $e');
      // }
      return;
    case 'open':
      return open();
    default:
      throw PlatformException(
        code: 'Unimplemented',
        details: 'mono_flutter for web doesn\'t implement \'${call.method}\'',
      );
  }
}