Closed pen110 closed 10 months ago
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. StateError (Bad state: GetIt: Object/factory with type SaveAppThemeUseCase 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?))
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
Yes I have this one, but the funny case is that where I always got the error dont use this dependency
@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