Skip to content

Instantly share code, notes, and snippets.

@ch8n
Last active October 21, 2022 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ch8n/663f5db0ca2e8b129a71276c1ea91320 to your computer and use it in GitHub Desktop.
Save ch8n/663f5db0ca2e8b129a71276c1ea91320 to your computer and use it in GitHub Desktop.
Delegate mutable state
// Create a counter state
var count by remember {
mutableStateOf(value = 0)
}
Column(
modifier = Modifier
.fillMaxSize()
.background(Color.White),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
// display state on UI
Text(
text = "$count", //👈 display current value of state
fontSize = 32. sp,
)
// click button to increment count by 2
Button(onClick = {
count = count + 1 // update state
count = count + 1 // update state
}) {
Text(text = "Increment by 2")
}// button end
} // column end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment