oday
07/03/2022, 3:44 PMlifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.uiState.collect { uiState ->
if (uiState.authenticated) {
setContent {
Home()
}
} else {
setContent {
Authentication()
}
}
}
}
}
and the issue is that it’s collecting the stateFlow immediately before my viewModel gets the chance return the result, so it shows Authentication, then when the value comes back ti shows Home again
I want it to…well observe like LiveData doesoday
07/03/2022, 3:47 PMdistinctUntilChanged
is trying to do with its signatureoday
07/03/2022, 3:51 PMif (uiState.authenticated != null) {
if (uiState.authenticated) {
setContent {
Home()
}
} else {
setContent {
Authentication()
}
}
}
but is that really how to do it ?oday
07/03/2022, 3:59 PMauthenticated
has an initial valueoday
07/03/2022, 4:09 PMAdam Powell
07/03/2022, 4:43 PModay
07/03/2022, 4:43 PModay
07/03/2022, 4:44 PMAdam Powell
07/03/2022, 4:46 PModay
07/03/2022, 4:46 PModay
07/03/2022, 4:46 PModay
07/03/2022, 4:47 PMAdam Powell
07/03/2022, 4:47 PMAdam Powell
07/03/2022, 4:47 PModay
07/03/2022, 4:47 PMAdam Powell
07/03/2022, 4:47 PMauthenticated
can't be a boolean because you're assuming that there's something special about, "not yet authenticated because I'm waiting on some sort of confirmation"Adam Powell
07/03/2022, 4:48 PModay
07/03/2022, 4:49 PModay
07/03/2022, 4:49 PModay
07/03/2022, 4:49 PMAdam Powell
07/03/2022, 4:49 PModay
07/03/2022, 4:49 PModay
07/03/2022, 4:49 PMAdam Powell
07/03/2022, 4:49 PModay
07/03/2022, 4:50 PMAdam Powell
07/03/2022, 4:50 PModay
07/03/2022, 4:50 PModay
07/03/2022, 4:50 PMAdam Powell
07/03/2022, 4:51 PMdistinctUntilChanged
by default and "skip" intermediate values if an observer isn't responding fast enough: it should never matter to an observer so long as the state is being modeled fully. The latest, current state is all you ever need.oday
07/03/2022, 5:35 PM