I want to save user preferences using Flutter\'s SharedPreference
. But the registered preferences are ALL null at new start (when app have been closed, not unis
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!