-1

i try to use shared preferences in flutter but i get this error and i tried to run flutter clear and still getting the same error

the error

ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)

Aliqua
  • 723
  • 7
  • 21
  • Does this answer your question? [Flutter Test MissingPluginException](https://stackoverflow.com/questions/44357053/flutter-test-missingpluginexception) – Uroš Aug 19 '20 at 04:03

3 Answers3

2

Have you add the SharedPreferences dependecies in pubspec.yaml.If not here's how you do it:

dependencies:
  flutter:
    sdk: flutter
  shared_preferences: ^0.5.8

From the error message I believe SharedPreferences don't have getAll method. Here's some example how you read data from SharedPreferences :

getStringValuesSF() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  //Return String
  String stringValue = prefs.getString('stringValue');
  return stringValue;
}
getBoolValuesSF() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  //Return bool
  bool boolValue = prefs.getBool('boolValue');
  return boolValue;
}
getIntValuesSF() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  //Return int
  int intValue = prefs.getInt('intValue');
  return intValue;
}
getDoubleValuesSF() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  //Return double
  double doubleValue = prefs.getDouble('doubleValue');
  return doubleValue;
}
Aldy Yuan
  • 1,795
  • 9
  • 23
0

After you adding a new package. You have to run

flutter pub get

Then rebuild you app.

sleepingkit
  • 598
  • 3
  • 8
0

for my case add setMockInitialValues({}) before sharedPreference.getInstance worked for me

SharedPreferences.setMockInitialValues({});
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
await sharedPreferences.setString(key, value);