how to use injectable and freezed package in flutter bloc?

78 views Asked by At

how to change the code below using the injectable and freezed package?

final getIt = GetIt.instance;
    
    class ServiceModule {
      ServiceModule._();
    
      static void init() {
    
        getIt
          ..registerSingletonAsync<CrashlyticsService>(() async {
            return FirebaseCrashlyticsService();
          })
          ..registerFactory<LogService>(DebugLogService.new)
          ..registerSingleton<LocalStorageService>(
            SharedPreferencesService(
              logService: getIt(),
            ),
            signalsReady: true,
          )
          ..registerSingleton<AppService>(
            AppServiceImpl(
              localStorageService: getIt(),
            ),
          );
      }
    }

I've done it like this before, but I get an error indicating that GetIt tried to look for CrashlyticsService, LogService, LocalStorageService, and App Service, but they weren't listed.

@module
    abstract class ServiceModule {
      @singleton
      CrashlyticsService get crashlyticsService => FirebaseCrashlyticsService();
    
      @factory
      LogService get logService => DebugLogService(
            logger: getIt(),
          );
    
      @singleton
      LocalStorageService get localStorageService => SharedPreferencesService(
            logService: getIt(),
          );
    
      @singleton
      AppService get appService => AppServiceImpl(
            localStorageService: getIt(),
          );
    }

this is my di_setup.dart


import 'package:get_it/get_it.dart';
import 'package:injectable/injectable.dart';

import 'di_setup.config.dart';

final getIt = GetIt.instance;

@InjectableInit(
  initializerName: r'$initGetIt', // default
  preferRelativeImports: true, // default
  asExtension: false, // default
)
void configureDependencies({String env = Environment.dev}) => $initGetIt(getIt, environment: env);
0

There are 0 answers