Xaphann
Xaphann

Reputation: 3677

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

Upvotes: 1

Views: 389

Answers (2)

Hampus
Hampus

Reputation: 346

For anyone else having this issue and the accepted answer not solving it. I found that building for web with html renderer solved the issue!

flutter build web --web-renderer html

Upvotes: 2

Xaphann
Xaphann

Reputation: 3677

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.

Upvotes: 0

Related Questions