Flutter SharedPreference do not persist

I had the same issue and fixed it in Android/../MainActivity.java by adding at the top:

import io.flutter.plugins.GeneratedPluginRegistrant;

As well as under super.onCreate(savedInstanceState);

GeneratedPluginRegistrant.registerWith(this);

The problem comes from using

SharedPreferences.setMockInitialValues({}); 

I got it from Flutter Test MissingPluginException but it seems to clear all the shared preferences.

However if you remove SharedPreferences.setMockInitialValues({}); and you don't have the two lines above in MainActivity.java, you'll get:

MissingPluginException(No implementation found for method getAll on channel flutter: plugins.flutter.io/shared_preferences)

I hope it helps!