import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:get_it/get_it.dart'; import 'package:in_app_purchase/in_app_purchase.dart'; import 'package:kuwot/core/app_updater.dart'; import 'package:kuwot/core/data/local/config.dart'; import 'package:kuwot/core/data/local/theme_mode_config.dart'; import 'package:kuwot/core/data/local/translation_target_config.dart'; import 'package:kuwot/core/env.dart'; import 'package:kuwot/core/network/network.dart'; import 'package:kuwot/core/presentation/bloc/config/theme_mode_cubit.dart'; import 'package:kuwot/core/presentation/bloc/config/translation_target_cubit.dart'; import 'package:kuwot/core/time.dart'; import 'package:kuwot/features/in_app_purchase/data/data_sources/remote/in_app_purchase_remote_data_source.dart'; import 'package:kuwot/features/in_app_purchase/data/repositories/in_app_purchase_repository_impl.dart'; import 'package:kuwot/features/in_app_purchase/domain/repositories/in_app_purchase_repository.dart'; import 'package:kuwot/features/in_app_purchase/domain/use_case/get_consumable_products.dart'; import 'package:kuwot/features/in_app_purchase/domain/use_case/listen_purchase.dart'; import 'package:kuwot/features/in_app_purchase/domain/use_case/purchase_consumable_product.dart'; import 'package:kuwot/features/in_app_purchase/presentation/bloc/in_app_purchase_bloc.dart'; import 'package:kuwot/features/in_app_purchase/presentation/bloc/purchase_details_cubit.dart'; import 'package:kuwot/features/in_app_update/presentation/bloc/in_app_update_bloc.dart'; import 'package:kuwot/features/quote/data/data_sources/remote/kuwot_api_remote_data_source.dart'; import 'package:kuwot/features/quote/data/repositories/quote_repository_impl.dart'; import 'package:kuwot/features/quote/domain/repositories/quote_repository.dart'; import 'package:kuwot/features/quote/domain/use_cases/get_background_images.dart'; import 'package:kuwot/features/quote/domain/use_cases/get_quote.dart'; import 'package:kuwot/features/quote/domain/use_cases/get_translated_quote.dart'; import 'package:kuwot/features/quote/domain/use_cases/get_translations.dart'; import 'package:kuwot/features/quote/presentation/bloc/background_images_bloc.dart'; import 'package:kuwot/features/quote/presentation/bloc/quote_bloc.dart'; import 'package:kuwot/features/quote/presentation/bloc/translations_bloc.dart'; import 'package:shared_preferences/shared_preferences.dart'; final getIt = GetIt.instance; void setup() { // network getIt.registerLazySingleton(() => NetworkImpl()); // shared preferences getIt.registerSingletonAsync(() async { final prefs = await SharedPreferences.getInstance(); return prefs; }); // env getIt.registerLazySingleton(() => EnvImpl()); // configs getIt.registerSingletonWithDependencies>( () => ThemeModeConfig(sharedPreferences: getIt()), dependsOn: [SharedPreferences], ); getIt.registerSingletonWithDependencies>( () => TranslationTargetConfig(sharedPreferences: getIt()), dependsOn: [SharedPreferences], ); // data sources getIt.registerLazySingleton( () => KuwotApiRemoteApiImpl(env: getIt(), network: getIt()), ); getIt.registerLazySingleton( () => InAppPurchaseRemoteDataSourceImpl(iap: getIt()), ); // repositories getIt.registerLazySingleton( () => QuoteRepositoryImpl(quoteDataSource: getIt()), ); getIt.registerLazySingleton( () => InAppPurchaseRepositoryImpl(inAppPurchaseDataSource: getIt()), ); // use cases getIt.registerLazySingleton(() => GetQuote(getIt())); getIt.registerLazySingleton( () => GetTranslatedQuote(getIt()), ); getIt.registerLazySingleton( () => GetBackgroundImages(getIt()), ); getIt.registerLazySingleton(() => GetTranslations(getIt())); getIt.registerLazySingleton( () => GetConsumableProducts(getIt()), ); getIt.registerLazySingleton( () => PurchaseConsumableProduct(getIt()), ); getIt.registerLazySingleton(() => ListenPurchase(getIt())); // blocs getIt.registerSingletonAsync(() async { final initialThemeMode = await getIt>().get(); return ThemeModeCubit( themeModeConfig: getIt(), initialThemeMode: initialThemeMode ?? ThemeMode.system, ); }, dependsOn: [SharedPreferences, Config]); getIt.registerLazySingleton( () => InAppUpdateBloc(appUpdater: getIt()), ); getIt.registerLazySingleton( () => InAppPurchaseBloc( getConsumableProducts: getIt(), purchaseConsumableProduct: getIt(), ), ); getIt.registerLazySingleton( () => PurchaseDetailsCubit(getIt()), ); getIt.registerSingletonAsync(() async { final initialTranslationTarget = await getIt>() .get(); return TranslationTargetCubit( translationTargetConfig: getIt(), initialTranslationTarget: initialTranslationTarget ?? defaultTranslationTarget, ); }, dependsOn: [SharedPreferences, Config]); getIt.registerFactory( () => QuoteBloc( getQuote: getIt(), getTranslatedQuote: getIt(), translationTargetConfig: getIt(), ), ); getIt.registerFactory( () => BackgroundImagesBloc(getBackgroundImages: getIt()), ); getIt.registerFactory( () => TranslationsBloc(getTranslations: getIt()), ); // others getIt.registerLazySingleton(() => AppUpdaterImpl()); getIt.registerLazySingleton