Persist Local Data
Pick the least powerful storage that satisfies durability, query, target, and privacy requirements.
Workflow
- Classify the data: preference, file, record, cache, secret, or sync source.
- Choose the target matrix: Android, iOS, desktop, web.
- Decide whether export/restore is required before sync.
- Write migrations before shipping schema changes.
- Test wipe, restore, upgrade, and low-storage behavior.
Starting Choices
| Data | Start with |
|---|---|
| Theme, onboarding flag, small primitive setting | shared_preferences |
| User-created exportable document | File APIs with platform paths |
| Queryable local records | SQLite-backed store |
| Offline-first app state | Local DB plus mutation queue and backup/export |
| Secrets | Platform secure storage and explicit recovery model |
Do Not Skip
migration test
export file smoke
restore smoke
delete account/data path
backup threat model
Gotcha:
shared_preferencesis not a database and should not hold critical records. It is for small primitive values.