get_it
get_it copied to clipboard
Why missing required factory parameter is silently replaced with null?
class SettingsBloc {
final Event event;
SettingsBloc(@factoryParam this.event);
}
The call getIt<SettingsBloc>()
works without crashes. But it shouldn't.
Why missing required parameter is considered expected behavior, and it is silently replaced with null? (Untill null pointer exception thrown somewhere).
This looks to me as if you are using injectable. I think get_it doesn't do anything like that.
It's not the problem with injectable. I can reproduce the same in pure get_it.
Registering:
GetIt.instance.registerFactoryParam<SettingsBloc, Event, dynamic>((event, _) => SettingsBloc(event));
then:
final bloc = GetIt.instance<SettingsBloc>()
and:
bloc.event == null
ah; it's a factory with parameters. yeah, get_it can't know what value you want to pass there. i I wonder if it would help to give them default values of ´Objec()´
I suppose, it should at least throw, when required param is not passed. And, of course, it shouldn't be null by default
could you creat a PR with a unit test for this?
@escamoteur Any solutions to this?