Код: Выделить всё
class MyViewmodel(repository: Repository, sv: SaveStateHandle): Viewmodel() {
var user by mutableStateOf(User(id = "", name = "")
private set
init {
user = User(id = sv.["id"], name = sv.["name"]) // here works perfectly the data is set
getInfo()
}
fun getInfo() {
//debuging here user data is ok
viewmodelScope.launch(Dispatchers.IO) {
repository.getInfo(id = user.id) // here's the problem user.id is empty
}
}
}
Я тестировал без Dispatchers.IO, и это работает, но мне нужно чтобы запустить его в потоке ввода-вывода, и я хотел бы знать, почему возникает эта ошибка, и найти какое-либо решение этой проблемы
Подробнее здесь: https://stackoverflow.com/questions/790 ... coroutines