Search code examples
flutterfirebaseflutter-web

Flutter Web shared_preferences and Firebase


When I try to use the shared_preferences locally for the web it works. When I publish the code to Firebase it returns the following error:

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

I have a button like this:

onPressed: ((() async {
    try {
      myData = !myData;
      var preferences = await SharedPreferences.getInstance();
      preferences.setBool('myData', myData);
    } catch (e) {
      debugPrint(e.toString());
    }
  })),
  icon: const Icon(Icons.question_mark),
  label: const Text('No work firebase'),
)

When running it locally for the web it works perfectly! When I deploy it to Firebase I get the error above.

If you care I am running the following commands to deploy:

flutter build web
firebase deploy

Solution

  • So it turns out it most likely was an issue with Flutter. After upgrading to Flutter 3.3.4 from 3.3.3 and deploying again it worked perfectly.