From the course: Exploring Ktor with Kotlin Multiplatform and Compose
Unlock this course with a free trial
Join today to access over 25,600 courses taught by industry experts.
Client integration - Kotlin Tutorial
From the course: Exploring Ktor with Kotlin Multiplatform and Compose
Client integration
- [Instructor] Now, let's connect the shared client with our composed UI, so everything flows smoothly. User tabs, API calls, local caching, and UI state updates. Look at Apod View Model to see how it acts as the bridge between the composed UI and the shared repository. When initialized, it calls repository methods and emits state via state flow. The composable collects this state using collect as state and renders whatever it receives, loading spinners, errors or data. The view model also handles user events. When the user pulls to the refresh, we call methods like refresh, which reruns the network calls and updates the state. No need to touch the UI code, just update the flow. Check out home screen to see this pattern in action. The view model loads paginated data and exposes a list of entries with flags like, is loading and has more data. When the composable detects scrolling to the end, it calls, load more items and the view model updates the state. The separation keeps things…