【Compose Multiplatform】手機本地持久化儲存DataStore實作
前言
在純 Android 專案中
我們可以直接使用原生的 DataStore
但在 Compose Multiplatform 專案中
如何繼續無痛使用 DataStore 呢?
本文將介紹如何在跨平台環境中
實現 DataStore 的本地化儲存
實作步驟
在 build.gradle.kts 中添加:
Android 平台實作:
iOS 平台實作:
總結
- Compose Multiplatform 允許我們在跨平台項目中使用 DataStore
- 通過適當的封裝,可以在不同平台上統一使用 DataStore API
- 使用 DataStore 可以簡化本地數據持久化的實現
- 結合 Koin 等依賴注入框架,可以更好地管理 DataStore 實例