From the course: Android Compose with Kotlin
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Pass data in a ViewModel - Kotlin Tutorial
From the course: Android Compose with Kotlin
Pass data in a ViewModel
- [Instructor] Currently, our day filter chips do nothing. We want to wire them up so that they properly filter the list of sessions. I've already added a click handler for us to the SessionScreen, onDayClick, which you can see here on line number 51, and I've weaved it through the necessary composables. We now need to add the support to our ViewModel. So let's move there. When we take a look at our constructor, besides the ConferenceRepository, we have a SavedStateHandle here on line number 23. The SavedStateHandle will ensure persistence across configuration changes and process that. Let's use it. Inside of our initialization function, what we want to do is get a reference to our SavedStateHandle, look for the key, day, and then listen for any changes to that day variable. To do this, I'm going to slightly refactor what we have so far. Instead of storing our data inside of the sessionInfos variable, I'm going to directly make that call here on line number 49. So I'll remove this…
Contents
-
-
-
-
-
-
-
-
(Locked)
Explore lazy layouts in Compose5m 47s
-
(Locked)
Add a LazyGrid to a composable screen6m 24s
-
(Locked)
Handle lazy layout item click events4m 11s
-
(Locked)
Handle loading and empty states7m 53s
-
(Locked)
Display snackbar messages6m 4s
-
(Locked)
Pass data in a ViewModel3m 54s
-
(Locked)
Challenge: Adding some polish1m 36s
-
(Locked)
Solution: Adding some polish2m 9s
-
(Locked)
-
-
-