Jetpack Compose isn’t updating my user state since I implemented nested navigation.
After the user logs out I set my UserStateModel to null.
Copy code
private val _userStateFlow: MutableStateFlow<UserStateModel?> = MutableStateFlow(UserStateModel())
val userStateFlow: StateFlow<UserStateModel?> = _userStateFlow
in my MainViewModel I’m collecting this state and i’m passing the user state down the hierarchy.
Before implementing nested navigation everything got updated accordingly but since I implemented nested navigation the change get’s lost somewhere inside my navigationGraph.
Anyone else faced this problem?
Aaron Waller
09/16/2022, 3:44 PM
My MainViewModel:
Copy code
private val _mainUserState: MutableState<UserStateModel?> = mutableStateOf(null)
val mainUserState: State<UserStateModel?> = _mainUserState
init {
viewModelScope.launch {
authRepository.getUserState().collect() {
_mainUserState.value = it
}
}
}
My MainActivity:
Copy code
val userState by mainViewModel.mainUserState
and from there I’m passing this userState down the hierarchy