iam using provider and get_it package while running the app it shows this error

249 views Asked by At

Bad state: GetIt: Object/factory with type Dio is not registered inside GetIt. (Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance; Did you forget to register it?)

i add dio inside the get_it service but it still shows the same error

`Future\<void\> setup() async {
// sl.registerSingleton(Dio(sl()));
sl.registerSingleton(() =\> Dio());
sl.registerLazySingleton(() =\> DioClient(AppConstants.apiBaseURL, sl(),
loggingInterseptor: sl(), sharedPreferences: sl()));
sl.registerLazySingleton\<LoggingInterseptor\>(() =\> LoggingInterseptor());
sl.registerLazySingleton(() =\> SharedPreferencesProvider());

// User:----------------------------------------------------------------------
sl.registerLazySingleton(() =\> AuthProvider(authRepoUser: sl()));
sl.registerFactory(() =\> AuthRepoUser(
dioClient: sl(),
));
}\`
1

There are 1 answers

0
Dewa Prabawa On

You need to specify the type of the instance when you register it to get it: example:

  sl.registerLazySingleton<RemoteDataSource>(
        () => RemoteDataSourceImpl(sl()));