Код: Выделить всё
val uiState: StateFlow = busDataRepository.getBusStops()
.map { busStops ->
BusStopsDBScreenUiState.Success(busStops, Res.string.bus_stops_db_filled)
}
.catch { throwable ->
emit(BusStopsDBScreenUiState.Error(throwable))
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), BusStopsDBScreenUiState.Loading)
fun updateBusStops() {
viewModelScope.launch(Dispatchers.Main) {
launch(Dispatchers.IO) {
busDataRepository.updateBusStops()
}
}
}
Код: Выделить всё
sealed interface BusStopsDBScreenUiState {
object Loading : BusStopsDBScreenUiState
data class Error(val throwable: Throwable) : BusStopsDBScreenUiState
data class Success(
val data: List,
val dialogText: StringResource?
) : BusStopsDBScreenUiState
}
моего пользовательского состояния Sucess на нулевое значение, чтобы скрыть диалоговое окно, когда пользователь нажимает диалоговое окно. кнопка закрытия:
Код: Выделить всё
fun closeDialog() {
//TODO
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... -stateflow
Мобильная версия