Skip to content

Bad state: GetIt: Object/factory with type <?> is not registered inside GetIt #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yusufkecer opened this issue Aug 13, 2024 · 1 comment

Comments

@yusufkecer
Copy link

yusufkecer commented Aug 13, 2024

I have been facing an error that I cannot solve since last night. When I run the callback function in the GenderAsset widget, the application gives an error. When I use GenderCubit instead of Locator.sl(), the error goes away. I leave the code and pages here. I'd be happy if you help.

Gender StflW

 Widget build(BuildContext context) {
    return BlocProvider(
      create: (context) => Locator.sl<GenderCubit>(),
      child: const _GenderView(),
    );
  }

Gender Widget

  body: Center(
        child: Padding(
          padding: const ProductPadding.ten(),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              GenderAsset(
                value: false,
                onChanged: (bool? value) {
                  print(context.read<GenderCubit>().genderValue); //error line
                },
                asset: AssetValue.female.value.lottie,
                gender: LocaleKeys.gender_fm.tr(),
                color: ProductColor().pink,
                icon: FontAwesomeIcons.venus,
              ),
            ],
          ),
        ),
      ),

init

@InjectableInit()
abstract final class Locator {
  static final sl = GetIt.instance;

  static Future<void> locateServices() async {
    sl.init();
  }
}

config

extension GetItInjectableX on _i174.GetIt { // initializes the registration of main-scope dependencies inside of GetIt   _i174.GetIt init({
    String? environment,
    _i526.EnvironmentFilter? environmentFilter,   }) {
    final gh = _i526.GetItHelper(
      this,
      environment,
      environmentFilter,
    );
    gh.lazySingleton<_i454.AppRouter>(() => _i454.AppRouter());
    gh.lazySingleton<_i46.BaseTheme>(() => _i46.BaseTheme());
    gh.factory<_i427.CacheMethods<_i906.BMIS>>(() => _i682.BMICache());
    gh.lazySingleton<_i162.ProductLocalization>(() => _i162.ProductLocalization(
          child: gh<_i409.Widget>(),
          key: gh<_i409.Key>(),
        ));
    gh.factory<_i427.CacheMethods<_i906.Users>>(() => _i575.UserCache());
    gh.factory<_i427.CacheMethods<_i906.Settings>>(() => _i138.AppCache());
    gh.factory<_i907.GenderCubit>(
        () => _i907.GenderCubit(genderValue: gh<_i110.GenderValue>()));
    return this;   } }
    

GenderValue

enum GenderValue {
  male,
  female,
}

GenderCubit

@injectable
class GenderCubit extends Cubit<GenderState> {
  GenderCubit({GenderValue? genderValue})
      : _genderValue = genderValue ?? GenderValue.male,
        super(SelectGender(genderValue: genderValue));

  GenderValue? _genderValue;


  void changeGender({GenderValue? newGender}) {
    _genderValue = newGender;
    emit(SelectGender(genderValue: _genderValue));
  }
}
@escamoteur
Copy link
Collaborator

escamoteur commented Aug 13, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants