часть кода в модели представления:
Код: Выделить всё
private val _audio = MutableStateFlow(Audio())
val audio: StateFlow get() = _audio
fun updateAudio(newAudio: Audio) {
Log.i(TAG, "updateAudio: ${audio.value}")
_audio.value = newAudio
Log.i(TAG, "updateAudio: ${audio.value}")
}
...
value of _audio.value changes, but subscribers are not notified
log:
updateAudio: Audio(id=-1, title=Dj Ess - Change My Wayz Mixxx, artist=, ...)
updateAudio: Audio(id=-1, title=lungskull - magic, artist=, ...)
Код: Выделить всё
@Composable
fun PlayingTrackBottomBar(
onClick: (Audio) -> Unit = {},
playerServiceViewModel: PlayerServiceViewModel = koinViewModel()
) {
val audio by playerServiceViewModel.audio.collectAsState()
...
}
Код: Выделить всё
viewModelScope.launch {
audio.collect {
Log.i(TAG, "init: $it")
}
}
Посмотрев логи, я обнаружил, что значение stateFlow меняется, но ни один из них не меняется. подписчики уведомлены
Подробнее здесь: https://stackoverflow.com/questions/787 ... t-notified
Мобильная версия