datastore-multiplatform

Implements Jetpack DataStore Preferences for user settings in Kotlin Multiplatform projects.

Updated Sep 12, 2026
One-click install
npx skills add https://github.com/Vierco/citoVisionApp --skill datastore-multiplatform-vierco
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: datastore-multiplatform
Source: https://github.com/Vierco/citoVisionApp/tree/main/.claude/skills/datastore-multiplatform
Command: npx skills add https://github.com/Vierco/citoVisionApp --skill datastore-multiplatform-vierco

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires androidx.datastore:datastore, androidx.datastore:datastore-preferences.

What problem does it solve? Storing simple user preferences (theme, language, onboarding flags) consistently across Android, iOS, and Desktop in Kotlin Multiplatform projects is error-prone: keys get duplicated as loose strings, IOExceptions leak to the UI, and sensitive data risks being stored unencrypted. This Skill defines a clean architecture for Preferences DataStore inside infrastructure/persistence with centralized keys, per-platform path resolution, and a typed Repository. ## Core Features & Use Cases - Cross-platform DataStore setup: Creates a single DataStore<Preferences> via PreferenceDataStoreFactory.createWithPath, with producePath() implemented per platform (Android filesDir, iOS NSDocumentDirectory, Desktop app data folder). - Typed Repository wrapper: Exposes domain-typed Flows and suspend setters (e.g., isOnboardingCompleted: Flow<Boolean>) with .catch { emit(emptyPreferences()) } so read failures fall back to defaults instead of crashing the UI. - Decision guidance: Clearly delimits when to use DataStore Preferences versus Room (relational data) versus secure storage (tokens, credentials), which is out of scope. - Use Case: You need to persist the user's onboarding-completed flag and last-used filter in a Compose Multiplatform app; this Skill gives you the key definitions, factory, Koin registration, and Repository implementation ready to adapt. ## Quick Start Ask the AI to implement a SettingsRepository using Jetpack DataStore Preferences in your Kotlin Multiplatform project following this Skill's architecture.

Frequently Asked Questions about datastore-multiplatform

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

FAQPage Schema
How do I use DataStore in Kotlin Multiplatform?▼

Add androidx.datastore and androidx.datastore-preferences to commonMain, then create the DataStore with PreferenceDataStoreFactory.createWithPath and a platform-specific producePath function. Only Preferences DataStore is supported in KMP; Proto DataStore remains Android-only.

DataStore vs Room: which should I use for app settings?▼

Use DataStore Preferences for simple key-value settings like theme, language, or feature flags. Use Room when data is relational, grows in volume, or needs queries such as lists, histories, or entity caches.

Can I store auth tokens in DataStore Preferences?▼

No. DataStore Preferences stores data in plain text, so tokens, passwords, and API keys must never be saved there unencrypted. Sensitive data requires platform-specific secure storage like Android Keystore or iOS Keychain.

Does Proto DataStore work on iOS and Desktop?▼

No. Proto DataStore is Android-only and not supported in Kotlin Multiplatform commonMain code. For strongly structured data across platforms, use Room instead.

Why does my DataStore flow crash with IOException?▼

A corrupted preferences file can make dataStore.data throw IOException. Apply .catch { emit(emptyPreferences()) } before mapping so reads fall back to default values instead of propagating the exception to the UI.