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

为NavigationSuiteScaffold加Crossfade动画时“it未使用”错误排查

解决Crossfade动画的"Target state parameter it is not used"错误

错误原因是你在Crossfade的内容lambda里没有使用它传入的目标状态参数it,而是直接引用了外部的currentDestination变量。Crossfade组件要求你使用它提供的这个参数来确保动画状态的一致性。

修改方法很简单,把when语句里的currentDestination替换成it即可:

Crossfade(
    targetState = currentDestination,
    label = "CurrentPage"
) {
    // 这里用it代替currentDestination
    when(it) {
        AppDestinations.HOME -> DestinationHome()
        AppDestinations.PROFILE -> DestinationProfile()
    }
}

如果你觉得it不够直观,也可以给参数指定一个明确的名称,比如destination:

Crossfade(
    targetState = currentDestination,
    label = "CurrentPage"
) { destination ->
    when(destination) {
        AppDestinations.HOME -> DestinationHome()
        AppDestinations.PROFILE -> DestinationProfile()
    }
}

这样修改后,既满足了Crossfade对参数使用的要求,也能保证动画切换时基于最新的目标状态渲染内容。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 23:09:53