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

Composable中clickable lambda传入action参数提示表达式未使用

问题原因与解决方法

你的问题出在clickable修饰符的lambda内部:你只是写了action,这仅仅是引用了这个函数类型的变量,并没有调用它,所以IDE提示"The expression is unused"。

要让点击Row时执行传入的action方法,需要在lambda里调用这个函数,也就是加上括号:action()。

修正后的完整代码:

@Composable
fun ClickableBar(text: String, action: () -> Unit) {
    Row(
        modifier = Modifier
            .height(40.dp)
            .background(color = AppPrimaryGreen)
            .fillMaxWidth()
            .clickable { action() }, // 这里改成action()
        verticalAlignment = Alignment.CenterVertically
    ) {
        Text(text = text)

        Icon(
            painter = painterResource(R.drawable.icon_arrow_right),
            contentDescription = "",
        )
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 09:19:52