What problem does it solve?
It provides a structured pattern for building robust Android UIs by using ViewModel with StateFlow to represent persistent UI state and SharedFlow for one-off events, ensuring state survives configuration changes and events don't re-trigger on rotation.
Core Features & Use Cases
- State-driven UI with StateFlow<UiState> backed by a private MutableStateFlow and exposed as a read-only StateFlow, ensuring thread-safe, reactive UI updates.
- One-off events with SharedFlow<UiEvent> configured with replay = 0 to prevent repeated events after configuration changes, with suspend or tryEmit sending mechanisms.
- UI integration guidance for Compose (collectAsStateWithLifecycle) and Views (repeatOnLifecycle) to observe state and events; architecture guidance to delegate work to UseCases or Repositories and to scope coroutines in viewModelScope.
- Real-world use case: A login screen that shows loading, success, or error states and navigates on success.
Quick Start
Create a simple ViewModel that initializes a StateFlow for UI state, a SharedFlow for one-off events, and a sample Compose screen observing these flows.