Home > Back-end >  Unsupported [References to variables aren't supported yet] in android jetpack compose
Unsupported [References to variables aren't supported yet] in android jetpack compose

Time:09-28

I want to use reference operator like onClick = ::onClose in below code

@Composable
    fun HeaderIcons(onClose: () -> Unit) {
    
        ConstraintLayout(
            modifier = Modifier
                .fillMaxWidth()
                .wrapContentHeight()
        ) {
                IconButton(
                    onClick = (::onClose)()
                ) {
                    Image(imageVector = ImageVector.vectorResource(id = R.drawable.ic_close), contentDescription = null)
                }
            }
        }
    }

I am facing error: Unsupported [References to variables aren't supported yet]

Anyone have idea how to solve it or any other alternative?

ThankYou in Advance.

CodePudding user response:

onClick = (::onClose)() isn't a valid syntax. You can't call a function reference.

Use onClick = onClose or onClick = { onClose() }.

CodePudding user response:

Composable function reference is not yet supported. You need to use:

onClick = {onClose()}
  • Related