Search code examples
android-layoutandroid-jetpack-composeandroid-jetpack

Change the Layout in Jetpack Compose


PROBLEM ::: I want to change the layout, more specifically hide or show the components in the layout based on the user click events.

I have attached a screen recording of the final result. PLEASE VISIT THIS LINK FOR FINAL RESULT

THINGS WHICH I CAN TRY ::: Create same layout with components and load that layout when user clicks on button. But I know it's the very inefficient way.


Solution

  • you can create a isVisible value and add the layout between an if braces.

    val isVisible = remember { mutableState(false) }
    if (isVisible) {
      content()
    }
    Button(onClick = { isVisible.value = true })