android-viewmodel

Community

Robust Android UI with ViewModel StateFlow.

Authorthinhtt264
Version1.0.0
Installs0

System Documentation

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.

Dependency Matrix

Required Modules

None required

Components

Standard package

💻 Claude Code Installation

Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.

Please help me install this Skill:
Name: android-viewmodel
Download link: https://github.com/thinhtt264/Snaplet-App/archive/main.zip#android-viewmodel

Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
View Source Repository

Agent Skills Search Helper

Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.