How to use a livedata as an argument for another function? Every time I get a null value, I guess the function is called before the livedata can return hence the null value. I'm not using it from a View. I'm using it from the viewmodel, the function updateFirstName is from the viewmodel. The token comes as a Flow from the Preference Store. All answers are appreciated thanks.
var token: LiveData<String> = appPreferenceStorage.accessToken.asLiveData()
@ExperimentalCoroutinesApi
private val _token: MutableLiveData<String>
get() = token as MutableLiveData<String>
fun updateFirstName(view: View) {
viewModelScope.launch {
profileRepository.updateFirstName(_token.value.toString(), "Bob", object : ProfileListener {
override fun onSuccess(response: String?) {
Timber.d(response)
}
override fun onFailure(localizedMessage: String?) {
Timber.e(localizedMessage)
}
})
}
}```