1.4, MutableStateList.toList not compatible with S...
# compose
a
1.4, MutableStateList.toList not compatible with SavedStateHandle?
maybe it wasn't supposed to work before, but we have been doing this for awhile to take a mutableStateList and store it in a SavedStateHandle by calling .toList() on it. (since this mutablestatelist is in a viewmodel not a rememberSaveable). with 1.4 I know it exposes the internals instead of making a copy, but that results in this:
Copy code
java.lang.IllegalArgumentException: Can't put value with type class androidx.compose.runtime.external.kotlinx.collections.immutable.implementations.immutableList.SmallPersistentVector into saved state
 	at androidx.lifecycle.SavedStateHandle.set(SavedStateHandle.kt:249)
(using lifecycle 2.6.0-rc01)
i
Is there a reason you aren't using SavedStateHandle's built in support for Composable state? That uses the right
autoSaver
a
Oh let me try that, this code has been around for awhile maybe before we had lifecycle 2.5
I can't use a mutableStateList with that though, I have to use simple state with a list member?
i
Our samples show both usages of
mutableStateListOf
,
mutableStateMapOf
, and
mutableStateOf
, they're all supported. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:lifecycl[…]/viewmodel/compose/samples/LifecycleViewModelSamples.kt;l=202
a
Ok sure, those examples are custom extracting/rebuilding it the mutablestatelist, I can try that. That should work..
v
We are facing the same crash after compose update to 1.4. Creating a new list from
MutableStateList
works fine but
MutableStateList.toList
cannot be serialized. Is it a known issue?
148 Views