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
相关产品推荐
相关产品推荐

