setupLocator function

Future<void> setupLocator()

Registers dependencies

Implementation

Future<void> setupLocator() async {
  final sharedPreferences = await SharedPreferences.getInstance();
  // locator.registerSingleton(sharedPreferences);
  if (!locator.isRegistered<SharedPreferences>()) {
    locator.registerSingleton(sharedPreferences);
  }

  // Local storage
  if (!locator.isRegistered<SecureStorage>()) {
    locator.registerLazySingleton<SecureStorage>(
      () => SecureStorageImpl(),
    );
  }

  // Navigation handler
  if (!locator.isRegistered<NavigationHandler>()) {
    locator.registerLazySingleton<NavigationHandler>(
      () => NavigationHandlerImpl(),
    );
  }

  // Init repository
  if (!locator.isRegistered<InitRepository>()) {
    locator.registerLazySingleton<InitRepository>(
      () => InitRepositoryImpl(
        cache: locator(),
        baseUrl: StringUtils.getBaseUrl(useV2Url: true),
      ),
    );
  }

  // User repository
  if (!locator.isRegistered<UserRepository>()) {
    locator.registerLazySingleton<UserRepository>(
      ({String? baseUrl}) => UserRepositoryImpl(
        cache: locator(),
        baseUrl: baseUrl ?? StringUtils.getBaseUrl(),
      ),
    );
  }

  // Payment repository
  if (!locator.isRegistered<PaymentRepository>()) {
    locator.registerLazySingleton<PaymentRepository>(
      ({String? baseUrl}) => PaymentRepositoryImpl(
        cache: locator(),
        baseUrl: baseUrl ?? StringUtils.getBaseUrl(),
      ),
    );
  }

  // Inspection repository
  if (!locator.isRegistered<InspectionRepository>()) {
    locator.registerLazySingleton<InspectionRepository>(
      ({String? baseUrl}) => InspectionRepositoryImpl(
        cache: locator(),
        baseUrl: baseUrl ?? StringUtils.getBaseUrl(),
      ),
    );
  }

  // Claim repository
  if (!locator.isRegistered<ClaimRepository>()) {
    locator.registerLazySingleton<ClaimRepository>(
      ({String? baseUrl}) => ClaimRepositoryImpl(
        cache: locator(),
        baseUrl: baseUrl ?? StringUtils.getBaseUrl(),
      ),
    );
  }

  // Form repository
  if (!locator.isRegistered<FormRepository>()) {
    locator.registerLazySingleton<FormRepository>(
      ({String? baseUrl}) => FormRepositoryImpl(
        cache: locator(),
        baseUrl: baseUrl ?? StringUtils.getBaseUrl(),
      ),
    );
  }

  // Product repository
  if (!locator.isRegistered<ProductRepository>()) {
    locator.registerLazySingleton<ProductRepository>(
      ({String? baseUrl}) => ProductRepositoryImpl(
        cache: locator(),
        baseUrl: baseUrl ?? StringUtils.getBaseUrl(),
      ),
    );
  }

  // Local cache
  if (!locator.isRegistered<LocalCache>()) {
    locator.registerLazySingleton<LocalCache>(
      () => LocalCacheImpl(
        sharedPreferences: locator(),
        storage: locator(),
      ),
    );
  }

  // //Local storage
  // locator.registerLazySingleton<SecureStorage>(
  //   () => SecureStorageImpl(),
  // );

  // // //Local storage
  // locator.registerLazySingleton<NavigationHandler>(
  //   () => NavigationHandlerImpl(),
  // );
  // locator.registerLazySingleton<InitRepository>(
  //   () => InitRepositoryImpl(
  //     cache: locator(),
  //     baseUrl: StringUtils.getBaseUrl(useV2Url: true),
  //   ),
  // );

  // locator.registerLazySingleton<UserRepository>(
  //   ({String? baseUrl}) => UserRepositoryImpl(
  //     cache: locator(),
  //     baseUrl: baseUrl ?? StringUtils.getBaseUrl(),
  //   ),
  // );

  // locator.registerLazySingleton<PaymentRepository>(
  //   ({String? baseUrl}) => PaymentRepositoryImpl(
  //     cache: locator(),
  //     baseUrl: baseUrl ?? StringUtils.getBaseUrl(),
  //   ),
  // );

  // locator.registerLazySingleton<FormRepository>(
  //   ({String? baseUrl}) => FormRepositoryImpl(
  //     cache: locator(),
  //     baseUrl: baseUrl ?? StringUtils.getBaseUrl(),
  //   ),
  // );

  // locator.registerLazySingleton<ProductRepository>(
  //   ({String? baseUrl}) => ProductRepositoryImpl(
  //     cache: locator(),
  //     baseUrl: baseUrl ?? StringUtils.getBaseUrl(),
  //   ),
  // );

  // locator.registerLazySingleton<LocalCache>(
  //   () => LocalCacheImpl(
  //     sharedPreferences: locator(),
  //     storage: locator(),
  //   ),
  // );
}