You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用youtube_player_flutter包遇PlatformException,视频无法播放求助

解决youtube_player_flutter在iOS模拟器中显示CircularProgressIndicator并触发PlatformException的问题

问题描述

集成youtube_player_flutter包后,在iPhone模拟器中尝试播放视频时,界面始终停留在CircularProgressIndicator,同时触发如下PlatformException:

Unhandled Exception: PlatformException(unregistered_view_type, A UIKitView widget is trying to create a PlatformView with an unregistered type: < com.pichillilorenzo/flutter_inappwebview >, If you are the author of the PlatformView, make sure registerViewFactory is invoked. If you are not the author of the PlatformView, make sure to call GeneratedPluginRegistrant.register., null)

已尝试在info.plist中添加io.flutter.embedded_views_preview和NSAllowsArbitraryLoads,但问题未解决。

解决方案

以下是针对该问题的分步排查和解决方法:

  • 重新安装并校验依赖
    youtube_player_flutter内部依赖flutter_inappwebview,依赖版本不兼容或安装不完整会导致PlatformView注册失败:

    1. 执行flutter clean清理项目缓存
    2. 删除iOS目录下的Podfile.lock文件
    3. 执行flutter pub get重新拉取依赖
    4. 进入iOS目录,执行pod install --repo-update更新Pod仓库并完成安装
  • 完善iOS项目配置
    除已添加的两项配置,还需确认:

    1. info.plist中io.flutter.embedded_views_preview的值设为YES
    2. NSAppTransportSecurity字典下,NSAllowsArbitraryLoads设为YES(测试场景可用,上线建议配置特定域名的例外规则)
    3. iOS项目的部署目标(Deployment Target)不低于iOS 11.0(flutter_inappwebview最低支持版本)
  • 重置模拟器状态
    模拟器缓存或异常状态可能引发问题:

    1. 关闭当前模拟器,从Xcode中重新启动
    2. 执行模拟器的「Erase All Content and Settings」操作,重置模拟器环境
  • 指定兼容的依赖版本
    若上述步骤无效,可在pubspec.yaml中直接指定与youtube_player_flutter兼容的flutter_inappwebview稳定版本,再重新执行依赖安装流程。

内容的提问来源于stack exchange,提问作者Raymond Idu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 08:36:05