java.lang.IllegalArgumentException: compose.runtime.snapshots.SnapshotStateList@430cd20 cannot be saved using the current SaveableStateRegistry

Viewed 27

I have these val:

val starters = rememberSaveable { mutableStateListOf<Course>() }
val firstcourses = rememberSaveable { mutableStateListOf<Course>() }
val secondcourses = rememberSaveable { mutableStateListOf<Course>() }
val sides = rememberSaveable { mutableStateListOf<Course>() }
val fruits = rememberSaveable { mutableStateListOf<Course>() }
val desserts = rememberSaveable { mutableStateListOf<Course>() }
val drinks = rememberSaveable { mutableStateListOf<Course>()}

And when I got this error when passing them to my function:

fun HomePage(
    list: SnapshotStateList<RestaurantPreview>,
    starters: SnapshotStateList<Course>,
    firstcourses: SnapshotStateList<Course>,
    secondcourses: SnapshotStateList<Course>,
    sides: SnapshotStateList<Course>,
    fruits: SnapshotStateList<Course>,
    desserts: SnapshotStateList<Course>,
    drinks: SnapshotStateList<Course>
){
....

The system suggest me to "Please consider implementing a custom Saver for this class and pass it to rememberSaveable()." Can somebody can help me?

1 Answers

To use rememberSaveable {} the type you are saving must be able to be saved to a Bundle.

In your case you will have to implement the saver using MapSaver or just use remember {}

Related