Read shared preferences in Flutter app that were previously stored in a native app Read shared preferences in Flutter app that were previously stored in a native app flutter flutter

Read shared preferences in Flutter app that were previously stored in a native app


As suggested here you can get the native file's content and copy it to a new file. You can copy the content to flutter's storage file when the user upgrades to your flutter app for the first time.


Best option is to store shared preferences in native part in same file as SharedPreferences plugin does it. So it means to do like that:

  1. In Java code replace your SharedPreferences code, with same key, as it is in plugin: SharedPreferences sharedPref = context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE);
  2. In native part save all preferences with prefix "flutter.". So in native part you will get needed preferences like this: String test = sharedPref.getString("flutter.test", "");


I am also aware of this plugin: https://pub.dev/packages/native_shared_preferences however, I can't believe that a third party plugin is the recommended way.

I think the third party plugin is just fine. The best thing about flutter is its amazing community that keeps contributing thoroughly to the ecosystem. That said, I would not recommend keeping using the non-official library. So you could test migrating your shared preferences behind the scenes.

  • In your initState query for flutter shared preferences.
  • If they exist, skip.
  • If they don't exist, query for native shared preferences, copy if exist

And done. This will help with the migration IMHO.