Search code examples
flutterdartdependency-injectionflutter-dependencies

Object/factory with type AuthBloc is not registered inside GetIt


i am getting error

Object/factory with  type AuthBloc 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?)
'package:get_it/get_it_impl.dart':
get_it_impl.dart:1
Failed assertion: line 372 pos 7: 'instanceFactory != null'

but i can the AuthBloc Register in the injectable config in here

extension GetItInjectableX on _i1.GetIt {
  // initializes the registration of main-scope dependencies inside of GetIt
  Future<_i1.GetIt> init({
    String? environment,
    _i2.EnvironmentFilter? environmentFilter,
  }) async {
    final gh = _i2.GetItHelper(
      this,
      environment,
      environmentFilter,
    );
    final firebaseInjectableModule = _$FirebaseInjectableModule();
    gh.lazySingleton<_i3.FirebaseAuth>(
        () => firebaseInjectableModule.firebaseAuth);
    gh.lazySingleton<_i4.FirebaseFirestore>(
        () => firebaseInjectableModule.firestore);
    gh.lazySingleton<_i5.IAuthCredentials>(() => _i6.FirebaseAuthenticator(
          gh<_i3.FirebaseAuth>(),
          gh<_i7.GoogleSignIn>(),
          gh<_i4.FirebaseFirestore>(),
        ));
    gh.factory<_i8.LoginFormBloc>(
        () => _i8.LoginFormBloc(gh<_i5.IAuthCredentials>()));
    await gh.factoryAsync<_i9.SharedPreferences>(
      () => firebaseInjectableModule.prefs,
      preResolve: true,
    );
    gh.factory<_i10.AuthBloc>(() => _i10.AuthBloc(gh<_i5.IAuthCredentials>()));
    return this;
  }
}

class _$FirebaseInjectableModule extends _i11.FirebaseInjectableModule {}

but i cant figure why i am getting that error in this code

class MyAppWidget extends StatelessWidget {
  const MyAppWidget({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MultiBlocProvider(
      providers: [
        BlocProvider(
          create: (context) =>
              getIt<AuthBloc>()..add(const AuthEvent.authCheckRequested()),
        ),
      ],
      child: MaterialApp.router(
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          primarySwatch: Colors.blue,
          textTheme: const TextTheme(
            displayLarge: TextStyle(fontSize: 16.0),
            displaySmall: TextStyle(fontSize: 15.0),
            displayMedium: TextStyle(fontSize: 15.0),
          ),
        ),
        routerConfig: AppRouter.router,
      ),
    );
  }
}

Solution

  • Solve

    it was given error which is not coming from the Auth, after converting my injectableinit to async

    @InjectableInit(preferRelativeImports: false)
    Future<void> configureInjection() async => await getIt.init();
    

    then all solved