-
-
Notifications
You must be signed in to change notification settings - Fork 153
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
Comments
You are using injectable which I don't really know. The error clearly tells you that the object you try to access is not registered inside get_it.
It's for sure not a bug in get_it but somehow your object does not get correctly registered.
Also why are you using get_it inside a provider?
If you decide to use get_it together with provider you should it only use where you don't have a context. Or Alternatively just use get_it.
I also recommend checking out watch_it as an alternative to using cubits
Am 13. Aug. 2024, 20:45 +0100 schrieb Yusuf Keçer ***@***.***>:
… 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;
GenderValue get genderValue => _genderValue!;
void changeGender2() {
print("changeGender2");
}
void changeGender({GenderValue? newGender}) {
_genderValue = newGender;
emit(SelectGender(genderValue: _genderValue));
}
}
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
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
Gender Widget
init
config
GenderValue
GenderCubit
The text was updated successfully, but these errors were encountered: