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

使用AnimatedSplashScreen配置pageTransitionType出现空检查错误如何解决?

错误触发原因

这个报错是animated_splash_screen: 1.1.0和page_transition: 2.0.1-nullsafety.0版本之间的API不兼容导致的:

构建AnimatedBuilder(animation: Listenable.merge([kAlwaysCompleteAnimation➩ProxyAnimation, kAlwaysDismissedAnimation➩ProxyAnimation]), dirty, state: _AnimatedState#bd6f7)时抛出_CastError:对空值使用了空检查运算符(Null check operator used on a null value)

animated_splash_screen 1.1.0版本开发时适配的是page_transition 1.x系列版本,page_transition从2.0版本开始对转场逻辑的参数进行了调整,新增了部分必填参数,同时修改了部分枚举的内部关联逻辑。animated_splash_screen 1.1.0调用page_transition的转场方法时,没有传入2.x版本要求的必填参数,导致参数为空时被空检查运算符强制调用抛出异常。

可行解决方案
  • 方案一:降级page_transition到兼容版本
    将pubspec.yaml中的page_transition版本改为^1.1.7+1,这个版本和animated_splash_screen 1.1.0完全适配,修改后执行flutter pub get重新拉取依赖即可解决问题。
animated_splash_screen: ^1.1.0
page_transition: ^1.1.7+1
  • 方案二:升级animated_splash_screen到适配2.x版本的最新版
    目前animated_splash_screen的最新版本已经完成了对page_transition 2.x的适配,你可以将依赖升级为如下版本,执行flutter pub get后即可正常使用:
animated_splash_screen: ^3.3.0
page_transition: ^2.0.1-nullsafety.0
  • 方案三:临时兼容方案(不修改依赖版本)
    如果不想改动当前的依赖版本,可以在AnimatedSplashScreen组件中额外传入curve和transitionDuration两个参数,补全page_transition 2.x要求的必填项即可避免空值报错:
AnimatedSplashScreen(
  splash: Icon(Icons.person),
  pageTransitionType: PageTransitionType.scale,
  transitionDuration: Duration(milliseconds: 500),
  curve: Curves.easeInOut,
  nextScreen: HomePage()
)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.05 07:00:04