Created
October 17, 2022 13:39
-
-
Save ch8n/20bcfb439f418cc09ae29a0dd783a492 to your computer and use it in GitHub Desktop.
increment by 2 using destrcuture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a counter state | |
val(count, setCount) = remember { | |
mutableStateOf(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 = { | |
setCount(count + 1) //π update state 1st time | |
setCount(count + 1) //π update state 2nd time | |
} | |
) { | |
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