StateValue

class StateValue<T : Any>(handle: SavedStateHandle, key: String, serializer: KSerializer<T>, json: Json = Json, default: T? = null) : ReadWriteProperty<Any?, T?> (source)

Serialized property delegate. Bind a property or supply a key before calling flow.

Constructors

Link copied to clipboard
constructor(handle: SavedStateHandle, key: String, serializer: KSerializer<T>, json: Json = Json, default: T? = null)

Types

Link copied to clipboard
object Companion

Read fallbacks do not persist another value; assignments still update the saved property.

Functions

Link copied to clipboard
fun <T : Any> StateValue<T>.default(default: () -> T?): FallbackValue<T, T?>

Supplies a nullable fallback on reads and observation, without writing it to the handle.

Link copied to clipboard
fun flow(): StateFlow<T?>

Stable immediate observable state. The handle key is private; update through this delegate.

Link copied to clipboard
fun get(): T?

Current value; defaults only initialize absent keys.

Link copied to clipboard
open operator override fun getValue(thisRef: Any?, property: KProperty<*>): T?

Reads the payload saved under the resolved property key.

Link copied to clipboard
operator fun provideDelegate(ref: Any?, property: KProperty<*>): StateValue<T>

Resolves an implicit key once, when the property is declared.

Link copied to clipboard
fun <T : Any> StateValue<T>.required(default: () -> T): FallbackValue<T, T>

Supplies a non-null fallback on reads and observation, without writing it to the handle.

Link copied to clipboard
fun set(value: T?)

Saves synchronously. Encoding failures leave the old value intact. Null does not remove the key.

Link copied to clipboard
open operator override fun setValue(thisRef: Any?, property: KProperty<*>, value: T?)

Serializes the assignment before replacing the saved payload.