Hi, I'm trying to use rememberSaveable with Enum b...
# compose
s
Hi, I'm trying to use rememberSaveable with Enum but it's not working, not sure what I'm doing wrong here.
Copy code
var selectedDashboardTab = rememberSaveable(TabSaver) { mutableStateOf(DashboardTab.HOME) }
Copy code
val TabSaver = Saver<DashboardTab, Int>(
    save = {
        if (it == DashboardTab.HOME) {
            0
        } else 1

    },
    restore = {
        if (it == 0) {
            DashboardTab.HOME
        } else {
            DashboardTab.STORE
        }
    }
)
Going to screen B and coming to Screen A doesn't save the state.
s
It's probably because stateSaver is the second parameter. You should explicity add
stateSaver = TabSaver
.
a
as far as I remember enums are serializable, so it should work without custom saver
s
After wasting so much time I get rid of it 😞 I tried stateSaver , saver, without Custom saver nothing works.