Computer scienceMobileJetpack ComposeComposablesMaterial

Checkbox, Radio Button, and Switch

Switch it off

Report a typo

Rearrange the following code lines to create a Switch and a Text composable below it. The Text should dynamically display "On" when the Switch is checked, and "Off" when it's unchecked.

Switch

Reorder lines using drag or arrows. Adjust indentation with left buttons
                Column {
              
                )
              
                @Composable
              
                var switchState by remember { mutableStateOf(false) }
              
                onCheckedChange = { switchState = it }
              
                }
              
                }
              
                checked = switchState,
              
                fun SwitchExample() {
              
                Text("State: ${if (switchState) "On" else "Off"}")
              
                Switch(
              

Create a free account to access the full topic