l

    loloof64

    1 year ago
    Hi ! Looking at https://developer.android.com/jetpack/compose/state, it is written that we may need to create custom object saver to pass custom data to
    rememberSaveable
    , but how should I build such object ? Let's say for
    data class Point(val x: Int, val y:Int)
    ? Because there is not any example in the documentation, and I did not understand this sentence (
    build a custom object saver
    ), what interface should the saver have ? What is the Android class/object responsible for such interface ? Should I create a
    Bundle
    myself ?
    l

    loloof64

    1 year ago
    Thank you @Jorkoh. I've also managed by using a simple String serialization
    Here what I've achieved
    Jorkoh

    Jorkoh

    1 year ago
    I think the
    mapSaver
    sample would work nicely for this case but doing it with a String also works 👍
    Albert Chang

    Albert Chang

    1 year ago
    You should use
    rememberSaveable(stateSaver = saver) { mutableStateOf(state) }
    and remove the
    MutableState
    type from your saver.
    l

    loloof64

    1 year ago
    Thank you @Albert Chang. I've tried to remove
    mitableStateOf
    from the saver, but this time I get an error
    Type 'DndData' has no method 'getValue(Nothing?, KProperty<*>)' and thus it cannot serve as a delegate
    .
    Albert Chang

    Albert Chang

    1 year ago
    You shouldn't remove the
    mutableStateOf()
    in
    rememberSaveable
    . If you didn't, check if you are using the correct overload of
    rememberSaveable
    .
    l

    loloof64

    1 year ago
    Thank you, in this attempt I get an error
    inferred data is MutableState<DndData> but type DndData expected
    .
    Albert Chang

    Albert Chang

    1 year ago
    You are using the wrong overload. You need to use the version with
    stateSaver
    parameter.
    l

    loloof64

    1 year ago
    Thank you, it worked. And I can use delegation with
    by
    again.