Jetpack Compose isn’t updating my user state since...
# compose
a
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?
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
r
Is it this?
a
Yess thank you! Is this supposed to not work? Or is it a bug?
r
I don’t know, it seems to be designed this way. It’s come up a few times but I have not seen any comment from Google.