Skip to content

Instantly share code, notes, and snippets.

@rajendhirandev
Created September 15, 2022 09:51
Show Gist options
  • Save rajendhirandev/369ef9dc718ffda52606dd23a6a02903 to your computer and use it in GitHub Desktop.
Save rajendhirandev/369ef9dc718ffda52606dd23a6a02903 to your computer and use it in GitHub Desktop.
Stateful Compose Sample
@Composable
fun MyCounterStateful() {
var vStart by remember { mutableStateOf(5) }
var vEnd by remember { mutableStateOf(7) }
var noOfTimes by remember { mutableStateOf(0) }
ComposePracticesTheme {
Column(modifier = Modifier.padding(15.dp)) {
Text(text = "Welcome to the Counter")
Button(onClick = {
noOfTimes++
}) {
val msg = if (noOfTimes == 0)
"Click Me"
else
"I've Clicked by $noOfTimes times"
Text(text = msg)
}
AnimatedVisibility(visible = noOfTimes in vStart..vEnd + 1) {
Text(
text = "I'm Visible between $vStart to $vEnd",
modifier = Modifier
)
if (noOfTimes == vEnd + 1) {
vStart = noOfTimes + 5
vEnd = vStart + 2
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment