美文网首页
flutter与iOS交互flutter端通道封装

flutter与iOS交互flutter端通道封装

作者: Leo_L | 来源:发表于2020-07-29 10:42 被阅读0次

    flutter与iOS原生交互通道,flutter端通道书写简单封装。
    代码:

    /// channel 通道名称
    /// method  方法名称
    /// arguments 传递的参数
    class ChannelPlugin {
    
      final String channel;
      final String method;
      final dynamic arguments;
      const ChannelPlugin({@required this.channel, @required this.method, this.arguments});
    
      Future invokeMethod() async {
       var result;
        try {
          result = await MethodChannel(this.channel).invokeMethod(this.method,this.arguments);
          return Future.value(result);
        } on PlatformException catch (e) {
          return Future.error(e.toString());
        }
      }
    }
    

    相关文章

      网友评论

          本文标题:flutter与iOS交互flutter端通道封装

          本文链接:https://www.haomeiwen.com/subject/ischrktx.html