Skip to content

Instantly share code, notes, and snippets.

@rajendhirandev
Created September 15, 2022 09:51
Embed
What would you like to do?
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