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

执行pub get获取flutter_pdf_viewer失败,遇依赖版本冲突问题求助

解决flutter_plugin_pdf_viewer与google_fonts的版本冲突问题

执行flutter pub get时遇到如下版本冲突错误:

Because no versions of google_fonts match >3.0.1 <4.0.0 and google_fonts 3.0.1 depends on path_provider ^2.0.0, google_fonts ^3.0.1 requires path_provider ^2.0.0.
And because flutter_plugin_pdf_viewer >=1.0.7 depends on path_provider ^1.1.0, google_fonts ^3.0.1 is incompatible with flutter_plugin_pdf_viewer >=1.0.7.
So, because brain_school depends on both flutter_plugin_pdf_viewer ^1.0.7 and google_fonts ^3.0.1, version solving failed.

冲突原因:google_fonts ^3.0.1要求path_provider ^2.0.0,但flutter_plugin_pdf_viewer ^1.0.7依赖的是path_provider ^1.1.0,两个包对path_provider的版本需求不重叠,导致pub无法完成依赖解析。

可行的解决办法

  • 降级google_fonts到兼容版本:选择google_fonts 3.0.0以下的版本,比如^2.3.1,这类版本依赖的path_provider版本范围包含^1.1.0。修改pubspec.yaml中的依赖:

    google_fonts: ^2.3.1
    

    之后重新执行flutter pub get。

  • 升级flutter_plugin_pdf_viewer:查看该包的最新版本,如果开发者已经更新了依赖支持path_provider ^2.0.0,直接替换为最新版本即可:

    flutter_plugin_pdf_viewer: ^最新版本号
    

    注意:如果该包已停止维护,此方法可能无效。

  • 更换PDF查看依赖包:如果flutter_plugin_pdf_viewer长期未更新,可以考虑使用更活跃的替代包,比如pdfx或flutter_pdfview,这些包通常会跟进Flutter生态的最新依赖标准。

内容的提问来源于stack exchange,提问作者Brahim Oubalaout

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 05:42:44