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

2 Answers2

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
  • 538
  • 6
  • 11