Hi. I have a Room DB and DAO, which return flow. ...
# android
r
Hi. I have a Room DB and DAO, which return flow. Dao function accepts as a parameter ID of the Route-object. The ViewModel contains a StateFlow with the current route. Task is: 1. At current route changes must be updated parameters of DB-observing 2. At DB changes must be updated UI I've tried next construction, but it is not working, i don't receive DB-updates
Copy code
val routeStatusFlow = coordinator.sharedState
        .map { it.currentRoute }
        .distinctUntilChanged()
        .flatMapLatest {
            if (it != null) {
                combine(
                    tasksRepository.getTasksSummaryFlow(it.id, START_IDENT),
                    tasksRepository.getTasksSummaryFlow(it.id, END_IDENT),
                ) { start, end -> RouteStatusViewState(it.status, start, end) }
            } else flowOf(RouteStatusViewState())
        }
        .stateIn(
            scope = viewModelScope,
            started = SharingStarted.WhileSubscribed(LIFECYCLE_TIMEOUT_MS),
            initialValue = RouteStatusViewState(),
        )
What an I doing wrong?
not kotlin but kotlin colored 2
c
Image from iOS.jpg
r
Ok, no problem. It was a question about Kotlin Flows, but ok. The problem was found out
c
Next time when having issue with flow, you should ask in #C1CFAFJSK .
1
n
i didn't understand about construction