10

i am using shared_preferences: ^2.0.7 with flutter_background_service: ^0.1.5 in flutter but when call shared preferences give me the error

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

When working in the forground mode, the call is done correctly, this problem occurs only about the call in the background mode.

  • [flutter-unhandled-exception-missingpluginexceptionno-implementation-found-for](https://stackoverflow.com/questions/50687801/flutter-unhandled-exception-missingpluginexceptionno-implementation-found-for) – mohit yadav Sep 08 '21 at 10:39

2 Answers2

1

same issue's happend with me

in Background : it stores the value (checked by reading value after setting it)

in Foreground : it couldn't find any stored values

Solution

just reload the preference instance before Get & Set

 final prefs = await SharedPreferences.getInstance();
 prefs.reload();  // The magic line 
Omar Essam El-Din
  • 1,415
  • 14
  • 17
0

usually this happens when thirdparty pulgin files are not properly included in build apk , to avoid this try :

flutter clean
flutter pub get
flutter run

this will make sure proper build with required files.

Tip : when adding a new plugin to pubspec.yaml file avoid Hot reload and Hot restart make sure to build apk from scratch so that all required files included in your build.

MANISH
  • 2,883
  • 4
  • 11
  • 30