美文网首页
Unhandled Exception: PlatformExc

Unhandled Exception: PlatformExc

作者: 李小轰 | 来源:发表于2021-03-17 10:54 被阅读0次
问题描述

flutter-application项目中,我们开发维护了一个flutter-plugin用于业务逻辑与原生的交互,原生模块中使用了flutterView,并新建flutterEngine与flutterView相绑定,dart层我们用到了一个三方库用于播放视频 video-player。

现象:

只有在使用新建的flutterEngine进行onAttachedToEngine,才会报错,使用plugin自动关联的engine进行绑定时能正常播放

报错信息:

Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)

问题分析
  • plugin使用channel进行交互,channel与engine存在对应关系,engine负责绘制dart层ui,并桥接channel
  • video-player作为插件引入,默认channel与主工程的engine进行关联,此时当我们使用new engine进行videoPlayer的ui层绘制时,videoPlayer使用channel对原生进行数据交互,此时channel发送给了 new engine 的通道,但 new engine并没有与video-player插件进行绑定,所以会报错 Unable connection on channel
image.png
处理方案

将我们的new engine与video-player插件进行关联


image.png
具体代码:
newEngine.plugins.add(VideoPlayerPlugin()) //VideoPlayerPlugin由video-player

启发:


image.png

相关文章

网友评论

      本文标题:Unhandled Exception: PlatformExc

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