OtpStateSaver
Saves an OtpState for rememberSaveable, so a partly entered code survives configuration changes and process death:
var otp by rememberSaveable(stateSaver = OtpStateSaver) { mutableStateOf(OtpState(OtpLength.SIX)) }Content copied to clipboard
The length and charset are saved by name, with the code and the error mark. A numeric state is saved in the 0.1.0 format, and data saved without a charset restores as numeric. Saved data that cannot be restored (an unknown length or an invalid code) is dropped, and rememberSaveable starts from its initial value. Restoring fires no callback and does not report completion again (see OtpState.restore). The platform may write saved state to disk, code included.