I'm trying to use `savedInstanceState` with `Mutab...
# compose
s
I'm trying to use
savedInstanceState
with
MutableState
Copy code
val themeColor by savedInstanceState(user) { mutableStateOf(Color.Blue) }
but I'm getting this error:
java.lang.IllegalArgumentException: Please use savedInstanceState() if you want to save a MutableState
What am I doing wrong here?
s
If you work with immutable objects savedInstanceState can suit you more as it wraps the value into the MutableState.
g
So you need immutable object? If so why do you use mutableState? Just remove mutableStateOf
s
Oops
Let me see
s
I want to save the Color object but it's not supported so I was wrapping it in a mutable state
And no it's not mutable I got confused
And this gives the same error:
Copy code
var themeColor by rememberSavedInstanceState { mutableStateOf(Color.Black) }
I guess I'll have to add a saver to use
savedInstanceState
☝️ 1
z
I would implement a
Saver
and convert the
Color
to/from
Int
1
a
savedInstanceState is basically a shortcut for rememberSavedInstanceState { mutableStateOf(...) }. and yes, you need yo use rememberSavedInstanceState and provide a custom Saver for colors
✔️ 1