-
-
Save euri16/b42034b89b786452b35d62dc658781e7 to your computer and use it in GitHub Desktop.
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
@Composable | |
fun UserScreen(viewModel: UserViewModel = viewModel()) { | |
// Collect state from the ViewModel | |
val username by viewModel.username.collectAsStateWithLifecycle() | |
val age by viewModel.age.collectAsStateWithLifecycle() | |
Column(modifier = Modifier.padding(16.dp)) { | |
TextField( | |
value = username, | |
onValueChange = { viewModel.onUsernameChanged(it) }, | |
label = { Text("Username") } | |
) | |
Text(text = "Age: $age") | |
Button(onClick = { viewModel.onAgeIncrement() }, modifier = Modifier.padding(top = 8.dp)) { | |
Text("Increase Age") | |
} | |
Button(onClick = { viewModel.onAgeDecrement() }, modifier = Modifier.padding(top = 8.dp)) { | |
Text("Decrease Age") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment