I was building a viewModel in my project and and I wrote a LiveData set like this
private val _user = MutableLiveData<User>()
val user= _user
val id = _user.map {
if ( something ) {
value
} else {
null
}
}
the problem I faced is that when I observe "id" in a Fragment/Activity , I can recieve the updates from "id" LiveData but if I try to get current value from "id" via "id.value" it returns null even if the "_user" liveData is updated.
Is there any reason for that ? am I missing something ?
I encountered the same problem as you, and solved it by below code.
Usage example: