Skip to content

Instantly share code, notes, and snippets.

@aqua30
Created January 9, 2023 15:40
Show Gist options
  • Save aqua30/3eb7c46289f1bb3599d8630231f6ea75 to your computer and use it in GitHub Desktop.
Save aqua30/3eb7c46289f1bb3599d8630231f6ea75 to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val viewModel: MainViewModel by viewModels()
var isEligible by remember {
mutableStateOf(false)
}
LaunchedEffect(true) {
viewModel.isEligible.collect {
isEligible = it
}
}
Column(
modifier = Modifier
.fillMaxSize()
.background(Color.White),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "Eligibility = $isEligible",
fontSize = 20.sp,
modifier = Modifier.padding(top = 16.dp)
)
Button(
modifier = Modifier.background(
if (isEligible) Color.Green else Color.Gray
),
onClick = {
viewModel.creditScore((0..900).random())
viewModel.age((1..100).random())
}) {
Text(text = "Proceed")
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment