StateFlow and SharedFlow
Expose reactive state from your app.
Hot Flows
Unlike cold flows, StateFlow and SharedFlow are hot: they exist independently of collectors and can be shared among many.
StateFlow Is a State Holder
A StateFlow always holds one current value. New collectors immediately receive that latest value. It is perfect for UI state.
private val _count = MutableStateFlow(0)
val count: StateFlow<Int> = _count.asStateFlow()All lessons in this course
- Coroutine Basics and Scopes
- viewModelScope and Dispatchers
- Kotlin Flow Basics
- StateFlow and SharedFlow