Alexandru Hadăr
10/12/2022, 7:52 PMlogout
call to finish, how should we collect the flow result in a @Composable function?
The only way I could think of would be something like this:
@Composable
private fun ProfileScreen(
onUserLoggedOut: () -> Unit,
viewModel: UserProfileViewModel = viewModel()
) {
LaunchedEffect(key1 = Unit) {
viewModel.onUserLoggedOut.collect { userLoginState ->
when (userLoginState) {
UserLoginState.LOGGED_IN -> Unit // do nothing
UserLoginState.LOGGED_OUT -> onUserLoggedOut()
}
}
}
}
However, it seems a bit off. IS there any better solution to this?Kevin Healy
10/12/2022, 8:00 PMval userLoginState by viewModel.onUserLoggedOut.collectAsState()
LaunchedEffect(key1 = userLoginState) {
when (userLoginState) {
//do stuff
}
}
Kevin Healy
10/12/2022, 8:03 PMAlexandru Hadăr
10/12/2022, 8:14 PMKevin Healy
10/12/2022, 8:16 PMKevin Healy
10/12/2022, 8:20 PM