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

Flutter从3.3升级到3.10遇NullThrownError问题求助

解决Flutter 3.10升级后_discoveryapis_commons依赖的NullThrownError问题

问题背景

  • 从Flutter 3.3升级到3.10,因依赖冲突仅升级部分依赖,设备为Apple Silicon M1
  • 先碰到libarclite_iphoneos.a找不到的错误,按相关方案修复后,出现新错误:
../../../.pub-cache/hosted/pub.dev/_discoveryapis_commons-1.0.3/lib/src/resumable_media_uploader.dart:78:44: 
Error: The method 'NullThrownError' isn't defined for the class 'ResumableMediaUploader'.
  • 试过卸载重装CocoaPods、指定架构执行pod install、清理Flutter项目、切换到Xcode 14.3 Beta,都没解决,也找不到引发错误的依赖

解决方案

这个错误根源是_discoveryapis_commons 1.0.3版本和Flutter 3.10对应的Dart版本不兼容——Flutter 3.10用的Dart移除了NullThrownError类定义,换成了NullPointerException,但旧版本的_discoveryapis_commons还在调用废弃的API。

按以下步骤操作:

  1. 强制升级_discoveryapis_commons到兼容版本
    在项目的pubspec.yaml里添加依赖约束,强制使用1.0.5及以上的版本(该版本已经修复了NullThrownError的问题):
    dependencies:
      # 保留你原有的其他依赖
      _discoveryapis_commons: ^1.0.5
    
  2. 清理并重新拉取依赖
    执行下面的命令彻底清理缓存,更新所有依赖:
    flutter clean
    flutter pub get
    cd ios
    pod deintegrate
    pod install
    cd ..
    
  3. 验证修复效果
    重新运行Flutter项目,确认错误消失。

补充说明

如果你的项目里没有直接依赖_discoveryapis_commons,那它肯定是某个第三方依赖的间接依赖。通过添加上述约束,可以强制整个依赖链使用指定的兼容版本,避免间接依赖拉取旧版本导致的冲突。

内容的提问来源于stack exchange,提问作者Praneeth Peiris

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 03:30:19