Suman Saha
Suman Saha

Reputation: 131

SharedPreference loses data when updating the flutter app on App Store and Play Store

I have written a flutter app. The app is using sharedPreferences version 0.5.7 to store data. The issue is when I debug the app on my device, there is no data loss. But when it is published on Play Store and App Store, the consumers complained that when they updated the app their previous data got deleted. Why this might be happening? How to debug or stop this from happening in future?

Upvotes: 10

Views: 1728

Answers (3)

User Rebo
User Rebo

Reputation: 4630

For me it deleted the shared preferences, when I force installed an older app version (with lower build number) with the same app id. This probably doesn't affect published builds, as newer versions need to have a higher build number.

Upvotes: 0

Aviraj Patel
Aviraj Patel

Reputation: 170

I faced similar problem when in debug mode sharedPreference working perfectly but when in released version it was not working properly.

so i created apk using : flutter build apk --release --no-shrink

and it's working like charm even after updating from play store.

if you still face error can you please share your code for more information.

Upvotes: 2

Lerex
Lerex

Reputation: 343

According to the Flutter Team shared sharedPreferences should not be used for storing critical data.

"One thing to remebmer for sharedPreferences and presistend storage,there is no guarantee that the writes will be persisted to disk , so make sure you do not use it to store any critical data"

2 good alternatives are

  1. Hive NoSQL (https://pub.dev/packages/hive)

  2. SQFlite (https://pub.dev/packages/sqflite)

Upvotes: 1

Related Questions