kotlin-flow-state-event-modeling

Guide Kotlin Flow state and event modeling with StateFlow, SharedFlow, and Channel.

1|Updated Apr 2, 2026
One-click install
npx skills add https://github.com/leogallego/ansible-jane --skill kotlin-flow-state-event-modeling-leogallego
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-flow-state-event-modeling
Source: https://github.com/leogallego/ansible-jane/tree/main/skills/kotlin-flow-state-event-modeling
Command: npx skills add https://github.com/leogallego/ansible-jane --skill kotlin-flow-state-event-modeling-leogallego

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Helps engineers design and review Kotlin code that uses Flow primitives (StateFlow, SharedFlow, Channel) correctly, avoiding issues like lost events, stale values, and improper synchronization.

Core Features & Use Cases

  • Guidance on when to use StateFlow vs SharedFlow vs Channel
  • Best practices for MutableStateFlow.update and stateIn
  • Patterns for one-shot events, sentinel values, and synchronization

Quick Start

Write code that uses StateFlow for state, SharedFlow for events, and Channel for one-shot events in a sample screen.

Frequently Asked Questions about kotlin-flow-state-event-modeling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
When should I use StateFlow vs SharedFlow vs Channel for Kotlin UI events?

Use StateFlow for UI state requiring deterministic updates, SharedFlow for events needing specific sharing semantics, and Channel for one-shot events to prevent event loss in Kotlin Flow architectures.

How do I prevent event loss with Kotlin Flow one-shot navigation actions?

Prevent event loss in Kotlin Flow by using Channel for one-shot navigation events and applying explicit initialization strategies with safe sentinel value handling to ensure deterministic UI updates.

What is the best way to update MutableStateFlow atomically in Kotlin multiplatform projects?

The best way to update MutableStateFlow atomically is using the update extension function, which ensures safe synchronization and prevents stale values across Android, desktop, or multiplatform projects.

Does stateIn work for converting cold flows to shared state in Android?

Yes, stateIn works to convert cold flows into shared state by applying appropriate sharing semantics and explicit initialization strategies to ensure deterministic UI updates in Android environments.

Why does my Kotlin SharedFlow lose events during UI recomputation?

Kotlin SharedFlow loses events during recomputation when using inappropriate sharing semantics; switching to Channel for one-shot events or applying stateIn ensures safe handling and prevents event loss.

Can I use Kotlin Flow state modeling for desktop applications?

Yes, you can use Kotlin Flow state modeling for desktop applications by applying StateFlow, SharedFlow, and Channel patterns to ensure deterministic updates and safe synchronization across multiplatform projects.