flow

inline fun <T : Any> MMKV.flow(key: String, default: T? = null): Flow<T?>

Creates a cold Flow that emits the current value for key and subsequently emits on every change to that key in this MMKV instance.

Emission is based on the internal addEventListener mechanism provided by the wrapped DelegatedMMKV. The flow sends default when the key does not exist.

Return

A Flow<T?> that observes changes for key.

Parameters

key

The key to observe.

default

The value to emit when the key does not exist.

Throws

if the value cannot be decoded as T.


fun <T : Any> MMKV.flow(key: String, clazz: KClass<T>, default: T? = null): Flow<T?>

Creates a cold Flow that emits the current value for key and subsequently emits on every change to that key in this MMKV instance.

Emission is based on the internal addEventListener mechanism provided by the wrapped DelegatedMMKV. The flow sends default when the key does not exist.

Return

A Flow<T?> that observes changes for key.

Parameters

key

The key to observe.

clazz

The value's KClass

default

The value to emit when the key does not exist.

Throws

if the value cannot be decoded as T.