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
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?