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

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