-
-
Notifications
You must be signed in to change notification settings - Fork 153
7.6.0 Bad state: GetIt: Object/factory with type SettingsModel 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?) #325
New issue
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
Comments
can you provide a small repro project that shows that behaviour? I have to debug this to see what the reason is. |
I got also this exception with getIt ^7.6.0 Exception has occurred. import 'package:data/data.dart';
Future<void> initDataLayer() async {
//Product
getIt.registerLazySingleton<RemoteDataSource>(
() => RemoteDataSourceImpl(),
);
getIt.registerLazySingleton<ProductRepository>(
() => ProductRepositoryImpl(getIt()),
);
getIt.registerLazySingleton<FetchProductsUseCase>(
() => FetchProductsUseCase(repository: getIt()),
);
getIt.registerLazySingleton<FetchProductByIdUseCase>(
() => FetchProductByIdUseCase(repository: getIt()),
);
getIt.registerLazySingleton<FetchMenuItemsUseCase>(
() => FetchMenuItemsUseCase(productRepository: getIt()),
);
//Locale Storage
getIt.registerSingleton<Box<ProductModel>>(
await Hive.openBox(LocaleStorage.cart.name),
);
getIt.registerLazySingleton<LocaleDataSource>(
() => LocaleDataSourseImpl(products: getIt()),
);
//Theme
getIt.registerLazySingleton<ThemeRepository>(
() => ThemeRepositoryImpl(localeDataSource: getIt<LocaleDataSource>()),
);
//Here is throws exception
getIt.registerLazySingleton<SaveAppThemeUseCase>(
() => SaveAppThemeUseCase(themeRepository: getIt<ThemeRepository>()),
);
getIt.registerLazySingleton<GetAppThemeUseCase>(
() => GetAppThemeUseCase(themeRepository: getIt<ThemeRepository>()),
);
//Cart
getIt.registerLazySingleton<CartRepository>(
() => CartRepositoryImpl(localeDataSource: getIt()),
);
getIt.registerLazySingleton<GetCartItemsUseCase>(
() => GetCartItemsUseCase(cartRepository: getIt()),
);
getIt.registerLazySingleton<AddCartItemUseCase>(
() => AddCartItemUseCase(cartRepository: getIt()),
);
getIt.registerLazySingleton<DeleteAllCartItemsUseCase>(
() => DeleteAllCartItemsUseCase(cartRepository: getIt()),
);
getIt.registerLazySingleton<DeleteCartItemUseCase>(
() => DeleteCartItemUseCase(cartRepository: getIt()),
);
} |
I just got the same issue, but is not all the time, that's why is difficult to debug |
@AliAltiyev I just saw that you uses an async factory function in one of your registrations. I recommend reading the readme up from here https://github.com/fluttercommunity/get_it#asynchronous-singletons @oscarshaitan do you uses any async calls while registering too? Without a reproproject its hard for me to tell why this happens |
@oscarshaitan actually that way its fine, first to await and then to register |
Bad state: GetIt: Object/factory with type Model 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?),
get_it: ^4.0.2 is ok . but 7.6.0 , i dont know why
The text was updated successfully, but these errors were encountered: