You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi guys.
Kotlin guide recommends using asStateFlow to return read only StateFlow
private val _counter = MutableStateFlow(0) // private mutable state flow
val counter = _counter.asStateFlow() // publicly exposed as read-only state flow
// Backing property to avoid state updates from other classes
private val _uiState = MutableStateFlow(LatestNewsUiState.Success(emptyList()))
// The UI collects from this StateFlow to get its state updates
val uiState: StateFlow<LatestNewsUiState> = _uiState
I cannot find a good answer in the documentation what are the differences between these two approaches? What is added value for using the asStateFlow() ?
The text was updated successfully, but these errors were encountered:
Hi guys.
Kotlin guide recommends using
asStateFlow
to return read only StateFlowAndroid guide is using simple type cast though:
I cannot find a good answer in the documentation what are the differences between these two approaches? What is added value for using the
asStateFlow()
?The text was updated successfully, but these errors were encountered: