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

No implementation found for method getAll on channel plugins.flutter.io.

The above will occur when you setup the plugin for the first time, so it has to be reinstalled.

Therefore, uninstall and reinstall your application.


After doing a lot of research, I found the answer. Add this to your code before you use shared preferences.

SharedPreferences.setMockInitialValues({});

It is because if you use getAll where there is nothing, it will go crazy. I don't think it is anything to do with iOS. If you even use normal getString, the internal program uses getAll so it will still crash

EDIT

I have been receiving a lot of comments on how it does not persist data b/w sessions. What you can do to fix that is put it in a try and catch statement. In try, call sharedPreferences.get and catch the error and then do setMockInitialValues. If sharedPreferences.get does not give an error, it means there is already data and no need to set mock values replacing the old ones.

I am not sure if that will work so if anyone tries it and it helps in persisting data, let me know so that I can validate it for others

EDIT 2

Thanks to Edwin Nyawoli, I now know why it did not persist data in between sessions. While mine is a temporary and not a real solution, it still may help. If someone can help me recreate this issue on my new device, I can try to figure out a new solution. Please let me know if you are willing to upload your project to github so that I can recreate it. For now, I did some more research and believe this might help you:-

In /android/app/build.gradle

buildTypes {
    release {
        signingConfig signingConfigs.release

        minifyEnabled true
        useProguard true

        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

change to

buildTypes {
    release {
        signingConfig signingConfigs.release

        minifyEnabled true
        useProguard true

        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

This answer is not mine, its from this comment on a github issue https://github.com/flutter/flutter/issues/65334#issuecomment-760270219