Extension of SharedFlow
Learn stateFlow, how to use it on Android, and how to transform Flow into StateFlow.
StateFlow
The StateFlow
is an extension of the SharedFlow concept. It works similarly to SharedFlow when we set the replay
parameter to 1. It always stores one value, which can be accessed using the value
property.
Press + to interact
interface StateFlow<out T> : SharedFlow<T> {val value: T}interface MutableStateFlow<T> :StateFlow<T>, MutableSharedFlow<T> {override var value: Tfun compareAndSet(expect: T, update: T): Boolean}
Note: Please note how the
value
property is overridden insideMutableStateFlow
. In Kotlin, anopen val
property can be overridden ...