Bind SharedPreferences in classes by getx dependency injection in Flutter

Viewed 476

Is it possible to bind shareprefrences by Getx into some classes? I create a class like this:

class SplashBinding implements Bindings {
  @override
  void dependencies() {
    Get.lazyPut<SplashLocalDataSource>(() {
      final sharedPreferences =  SharedPreferences.getInstance();
      return  awaitSplashLocalDataSource(// inject here )
    });

  }
}

I want to inject shareprefrences into awaitSplashLocalDataSource constructor. SharedPreferences.getInstance() return a future . Should I inject future of sharedPreferences or It is possible to inject sharedPreferences reference ?

use to be I used Injecteble package and I inject sharedPreferences by @preResolve annotation but in getx how can I do that?

0 Answers
Related