Last active
October 21, 2022 22:12
-
-
Save ch8n/663f5db0ca2e8b129a71276c1ea91320 to your computer and use it in GitHub Desktop.
Delegate mutable state
This file contains 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 | |
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