binayshaw7777/Leaflekt-Maps / .agents/skills
material-3
VerifiedImplement Google's Material Design 3 (Material You) UI system. Primary: Jetpack Compose Material3 (MaterialTheme, components, adaptive layout). Also Flutter and limited web (@material/web, maintenance mode). Covers tokens, 30+ components, layout, theming, M3 Expressive (platform matrix), and accessibility. Use when: "material design", "MD3", "material you", "Jetpack Compose", "MaterialTheme", "material component", "md3 button".
Android ViewModel & State Management.md
View on GitHub---
name: android-viewmodel
description: Best practices for implementing Android ViewModels, specifically focused on StateFlow for UI state and SharedFlow for one-off events.
---
# Android ViewModel & State Management
## Instructions
Use `ViewModel` to hold state and business logic. It must outlive configuration changes.
### 1. UI State (StateFlow)
* **What**: Represents the persistent state of the UI (e.g., `Loading`, `Success(data)`, `Error`).
* **Type**: `StateFlow<UiState>`.
* **Initialization**: Must have an initial value.
* **Exposure**: Expose as a read-only `StateFlow` backing a private `MutableStateFlow`.
```kotlin
private val _uiState = MutableStateFlow<UiState>(UiState.Loading)
val uiState: StateFlow<UiState> = _uiState.asStateFlow()
```
* **Updates**: Update state using `.update { oldState -> ... }` for thread safety.
### 2. One-Off Events (SharedFlow)
* **What**: Transient events like "Show Toast", "Navigate to Screen", "Show Snackbar".
* **Type**: `SharedFlow<UiEvent>`.
* **Configuration**: Must use `replay = 0` to prevent events from re-triggering on screen rotation.
```kotlin
private val _uiEvent = MutableSharedFlow<UiEvent>(replay = 0)
val uiEvent: SharedFlow<UiEvent> = _uiEvent.asSharedFlow()
```
* **Sending**: Use `.emit(event)` (suspend) or `.tryEmit(event)`.
### 3. Collecting in UI
* **Compose**: Use `collectAsStateWithLifecycle()` for `StateFlow`.
```kotlin
val state by viewModel.uiState.collectAsStateWithLifecycle()
```
For `SharedFlow`, use `LaunchedEffect` with `LocalLifecycleOwner`.
* **Views (XML)**: Use `repeatOnLifecycle(Lifecycle.State.STARTED)` within a coroutine.
### 4. Scope
* Use `viewModelScope` for all coroutines started by the ViewModel.
* Ideally, specific operations should be delegated to UseCases or Repositories.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |