Код: Выделить всё
val employeeState: StateFlow =
employeeRepository.fetch()
.map(EmployeeDataUiState::Success)
.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5_000),
initialValue = EmployeeDataState.Loading,
)
< /code>
В моем репозитории: < /p>
suspend fun fetchEmployees() = flow {
try {
val result = employeesApiService.fetchEmployees()
emit(result)
} catch (e: Exception) {
//emit(emptyList())
}
}
< /code>
employeeRepository.fetch()
Подробнее здесь: https://stackoverflow.com/questions/775 ... in-android