Member-only story

`toggleable` Modifier In Jetpack Compose

Jayant Kumar🇮🇳
2 min readSep 1, 2023

--

Photo by Arthur Mazi on Unsplash

In this article we will be talking about toggleable modifier in Jetpack Compose.

Let’s understood through an example…. Suppose we have a Row and inside it we have a Text & CheckBox composable function , we want to make Row clickable so that CheckBox can check On/Off . This can be achieve through toggleable modifier.

@Composable
fun ToggleableModifierExample() {

var isCheck by remember { mutableStateOf(false) }

Column(
modifier = Modifier
.padding(20.dp)
.fillMaxSize(),
verticalArrangement = Arrangement.Center
) {

Row(
modifier = Modifier
.fillMaxWidth()
.toggleable(
value = isCheck,
onValueChange = { isCheck = it },
role = Role.Checkbox,
)
) {
Text(text = "Checkbox", modifier = Modifier.weight(1f), fontSize = 20.sp)
Checkbox(checked = isCheck, onCheckedChange = null)
}

}

}

As you can see above we have Text & CheckBox inside Row . Row is clickable through toggleable modifier.

  • value :- it indicates the…

--

--

Jayant Kumar🇮🇳
Jayant Kumar🇮🇳

Written by Jayant Kumar🇮🇳

Hello My name is Jayant Kumar, I am a software Engineer , specialist in Mobile Development (Android , IOS , Flutter , React Native and Ionic) from India 🇮🇳

Responses (2)