Model the screen as one sealed `UiState` using the loading/content/error (LCE) variants. Make state data immutable so Compose can reason about it reliably: ```kotlin @Immutable sealed interface FeedUiState { data object Loading : FeedUiState @Immutable data class Content(val items: ImmutableList<Post>) : FeedUiState @Immutable data class Error(val message: String?) : FeedUiState } class FeedViewModel( private val getFeed: GetFeedUseCase, ) : ViewModel() { private val _uiState = MutableStateFl...
Scanned 9/5/2026
Install to Claude Code
npx -y skills add HoangNguyen0403/agent-skills-standard --skill android-state --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Android State?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-android-state-4aadfc0f)More formats (shields.io, HTML) on the badges page.
Model the screen as one sealed `UiState` using the loading/content/error
(LCE) variants. Make state data immutable so Compose can reason about it
reliably:
```kotlin
@Immutable
sealed interface FeedUiState {
data object Loading : FeedUiState
@Immutable
data class Content(val items: ImmutableList<Post>) : FeedUiState
@Immutable
data class Error(val message: String?) : FeedUiState
}
class FeedViewModel(
private val getFeed: GetFeedUseCase,
) : ViewModel() {
private val _uiState = MutableStateFlow<FeedUiState>(FeedUiState.Loading)
val uiState = _uiState.asStateFlow()
init {
loadFeed()
}
fun loadFeed() {
viewModelScope.launch {
getFeed()
.onStart { _uiState.value = FeedUiState.Loading }
.catch { error ->
_uiState.value = FeedUiState.Error(error.message)
}
.collect { items ->
_uiState.value = FeedUiState.Content(items)
}
}
}
}
```
Expose the private `MutableStateFlow` only through `asStateFlow()`, trigger the
initial load in `init`, and perform loading and state transitions in
`viewModelScope`. The UI renders each sealed branch; it should not use
`LiveData` for this new state contract or maintain separate competing flows for
loading, data, and errors.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!