Created
January 9, 2023 15:40
-
-
Save aqua30/3eb7c46289f1bb3599d8630231f6ea75 to your computer and use it in GitHub Desktop.
This file contains 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
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