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

Dart项目依赖冲突求助:test_coverage不支持空安全致版本解析失败

解决Dart 3.2.6版本解析失败问题

问题根源

你遇到的版本解析失败,核心原因是test_coverage >=0.1.1不支持空安全,且其SDK约束为>=2.0.0-dev.66.0 <3.0.0,和你当前使用的Dart 3.2.6(完全支持空安全的高版本SDK)存在兼容性冲突。

可行解决方案

  • 替换为官方支持空安全的包:放弃test_coverage,改用官方维护的coverage包。修改pubspec.yaml中的依赖项:
    dependencies:
      # 移除test_coverage
      coverage: ^1.6.3 # 可使用最新稳定版本
    
    执行dart pub get更新依赖即可。
  • 降级Dart SDK版本:如果必须依赖test_coverage,可按照提示将SDK降级到2.19.6。在pubspec.yaml中指定SDK约束:
    environment:
      sdk: '>=2.19.6 <3.0.0'
    
    切换到对应版本的Dart SDK后重新执行dart pub get。
  • 自行迁移包到空安全:若test_coverage已停止维护,可fork其代码仓库,将SDK约束升级为>=2.12.0,完成空安全迁移,然后在pubspec.yaml中引用你的fork版本:
    dependencies:
      test_coverage:
        git:
          url: https://github.com/你的用户名/test_coverage.git
          ref: 你的分支名
    

原始错误信息

Because mrz_parser depends on test_coverage >=0.1.1 which doesn't support null safety, version solving failed.

The lower bound of "sdk: '>=2.0.0-dev.66.0 <3.0.0'" must be 2.12.0 or higher to enable null safety.
For details, see https://dart.dev/null-safety

You can try the following suggestion to make the pubspec resolve:

  • Try using the Dart SDK version: 2.19.6. See https://dart.dev/get-dart.
    Process finished with exit code 1

内容的提问来源于stack exchange,提问作者umair khan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 06:32:09