I'm at Google CodeLabs: And here is the code:
@Composable
fun WaterCounter(
modifier: Modifier = Modifier,
) {
var count by remember { mutableStateOf(0) }
Column(
modifier = modifier.padding(16.dp)
) {
if (count > 0) {
var showTask by remember { mutableStateOf(true) }
if (showTask) {
WellnessTaskItem(
taskName = "Have you taken your 15 minute walk today?",
onClose = { showTask = false })
}
Text(
text = "You've had $count glasses",
modifier = modifier.padding(16.dp)
)
}
Row(
modifier = modifier.padding(top = 8.dp)
) {
Button(
onClick = { count++ },
enabled = count < 10,
) {
Text(text = "add one")
}
Button(
onClick = { count = 0 },
modifier = modifier.padding(start = 8.dp)
) {
Text(text = "Clear water count")
}
}
}
}
I can't get this phrase: "Press the Clear water count button to reset count to 0 and cause a recomposition. Text showing count, and all code related to WellnessTaskItem, are not invoked and leave the Composition. showTask is forgotten because the code location where remember showTask is called was not invoked."
Please help me understand why show task is forgotten? What does it mean "the code was not invoked" and "it leaves the composition"?