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

Flutter集成Rive动画报错:Null无法转换为SMIBool类型求助

Flutter Rive动画报错:type 'Null' is not a subtype of type 'SMIBool' in type cast
  • 开发场景:Flutter应用集成Rive包,已在侧边栏实现下载动画图标,后续模仿原有风格自制了文件夹动画图标
  • 交互逻辑:侧边栏列表项被点击时触发高亮动画
  • 报错情况:添加自制文件夹动画后出现错误,错误信息如下:
type 'Null' is not a subtype of type 'SMIBool' in type cast

错误定位到side_menu.dart第56行。

我推测问题出在Rive动画的代码调用或动画文件配置环节,相关代码片段如下:

// 原有下载动画初始化(正常运行)
void _onDownloadRiveInit(Artboard artboard) {
  final controller = StateMachineController.fromArtboard(artboard, 'DownloadStateMachine');
  if (controller != null) {
    artboard.addController(controller);
    _downloadHighlighted = controller.findSMI('isHighlighted') as SMIBool;
  }
}

// 自制文件夹动画初始化(报错关联代码)
void _onFolderRiveInit(Artboard artboard) {
  final controller = StateMachineController.fromArtboard(artboard, 'FolderStateMachine');
  // 第56行代码
  _folderHighlighted = controller.findSMI('isHighlighted') as SMIBool;
}

可能的排查方向:

  • 自制Rive文件中,状态机名称是否与代码中的FolderStateMachine完全一致?
  • 状态机内是否存在名为isHighlighted的SMIBool类型参数?
  • 代码中是否未对controller做非空判断就直接调用findSMI?

恳请熟悉Rive的开发者帮忙分析问题并给出解决方案。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 17:15:02