MethodChannelFlutterMatter constructor

MethodChannelFlutterMatter()

Implementation

MethodChannelFlutterMatter() {
  methodChannel.setMethodCallHandler((call) async {
    matterPrint('methodChannel called: ${call.method} with arguments: ${call.arguments}');
    String m = call.method;
    dynamic p = call.arguments;
    try {
      final h = _handlers.firstWhereOrNull((element) => element.match(m, p));
      matterPrint('$h matched for $m');
      final result = await h?.call(m, p);
      if (result is TransportObject) {
        return result.encode();
      }
      return result;
    } catch (e, s) {
      matterPrint('setMethodCallHandler exception: $s');
      if (e is PlatformCallResult) {
        return e;
      }
      return createPlatformCallExceptionResult(unHandlerException, s.toString());
    }
  });
}