5

I am trying to test a function which makes an api call and save that data into shared preferences. I am mocking my api call but in that function when i am trying to get instance of shared preferences I am getting this error:

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

This is my test case code.

main() {
 // setup
group("Login", () {
setUp(() {
  flutterTest.TestWidgetsFlutterBinding.ensureInitialized();
});
test("Valid Creds Login", () async {
  final validRes = ExpectedResponses.login();
  final client = MockClient((request) async {
    final res = json.encode(validRes);
    return Response(res, 200);
  });
  ApiController.init(client);

  final user = await ApiController.login(
      email: "abc@gmail.com", password: "12345678");
  expectAsync0(() {
    expect(user.id, "1763");
  });
}, skip: false);
});
}
Abdul Wahib
  • 51
  • 1
  • 2
  • 1
    Does this help? https://stackoverflow.com/questions/44357053/flutter-test-missingpluginexception/44360235 – Benjamin Dec 23 '19 at 14:54
  • No. My issue is related to saving values in SharedPreferences. – Abdul Wahib Dec 23 '19 at 15:24
  • Have you fully rebuilt your app since installing the SharedPreferences package? Which version of the package and of Flutter are you using? – J. S. Dec 23 '19 at 15:42
  • I am running unit test for it, in actual application it is running fine. Shared Preferences: 0.5.6 | Flutter: 1.12.13+hotfix.6 – Abdul Wahib Dec 23 '19 at 15:47
  • This helped me https://stackoverflow.com/questions/44357053/flutter-test-missingpluginexception/44360235 – chinloyal Aug 01 '20 at 00:59

3 Answers3

0

In my case this error solved by flutter clean command on terminal.

0

Below code is working perfect in my android project.

  class MainActivity : FlutterActivity() {

     override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {

             GeneratedPluginRegistrant.registerWith(flutterEngine)
      }
    }
Faisal Ahmed
  • 816
  • 9
  • 12
0

Error : No implementation found for method getAll on channel plugins.flutter.io/shared_preferences

Solution: Invalidate Caches worked in my case.