Why it's not possible to directly set the mutableLiveData.value when using a suspend function? See following code:
private val _clubs: MutableLiveData<List<ClubEntity>> by lazy {
MutableLiveData<List<ClubEntity>>().also {
fetchClubListFromRepository()
}
}
private fun fetchClubListFromRepository() {
viewModelScope.launch {
// This does NOT work, no error but the UI does not update.
// _clubs.value = clubsRepository.getAllClubs()
// This works, the UI updates.
var clubsList = clubsRepository.getAllClubs()
_clubs.value = clubsList
}
}
suspend fun getAllClubs(): List<ClubEntity> = withContext(Dispatchers.IO) {
ClubsApi.RETROFIT_SERVICE.getClubs()
}
> by lazy { fetchClubListFromRepository() }` ? After modifying method of course.
– SkypeDogg Jul 11 '22 at 14:45>`