We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This is what goes into my injection_container.dart file
final sl = GetIt.instance; Future init() async { //Bloc sl.registerFactory( () => NumberTriviaBloc( inputConverter: sl(), concrete: sl(), random: sl(), ), ); //Data - source sl.registerLazySingleton<NumberTriviaLocalDataSource>( () => NumberTriviaLocalDataSourceImpl(sl())); //External sl.registerLazySingleton(() async => await SharedPreferences.getInstance()); sl.registerLazySingleton(() => client.Client()); sl.registerLazySingleton<DataConnectionChecker>( () => DataConnectionChecker()); }
And this is how I use it in main.dart
void main() async{ WidgetsFlutterBinding.ensureInitialized(); await di.init();
runApp(MyApp()); }
This is the error i get in my console Exception: Object of type SharedPreferences is not registered inside GetIt
The text was updated successfully, but these errors were encountered:
I later got it solved by
Making the init function a asynchronous one using async
creating a variable to get an instance of Sharedpreference,
final spref =await SharedPreference.getInstance();
then sl.registerSingleton<SharedPreference>(() async => spref);
sl.registerSingleton<SharedPreference>(() async => spref);
Sorry, something went wrong.
you should use registerAsyncSingleton for this
No branches or pull requests
This is what goes into my injection_container.dart file
And this is how I use it in main.dart
void main() async{
WidgetsFlutterBinding.ensureInitialized();
await di.init();
runApp(MyApp());
}
This is the error i get in my console
Exception: Object of type SharedPreferences is not registered inside GetIt
The text was updated successfully, but these errors were encountered: