Hi all, I'm doing an app with large forms. To simp...
# compose
m
Hi all, I'm doing an app with large forms. To simplify things I'm trying to group the state of a form in a class. Something like:
Copy code
data class FormData(
	val name: String,
	val surname: String,
	val age: TextFieldValue,
	val location: Location)
data class Location(val lat: TextFieldValue, val long: TextFieldValue)
Some of the values are stored as String, but some are TextFieldValue, because I need to play with cursor postions sometimes. With this I do create a single mutable state:
Copy code
val formData = remember { mutableStateOf(FormData()) }
Until here everything works fine. The problem is when I try to persist the field values on screen rotation changes. To fix this I need to use rememberSaveable, but to do so, I need the FormData to be saveable (a Save<FormData, Any> class), but I find creating the Save implementation is very berbose, and prone to errors on modifications. Is there any other way to do this? I've been playing with using Serializable with Save, but many attributs of TextFieldValue are internal, so the only way to recreate it is with the Save method. I've managed a solution but mixing the both worlds, but I thing there must be something easier.