Skip to content
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

Why missing required factory parameter is silently replaced with null? #136

Open
AlexanderFarkas opened this issue Dec 8, 2020 · 6 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@AlexanderFarkas
Copy link

AlexanderFarkas commented Dec 8, 2020

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).

@AlexanderFarkas AlexanderFarkas changed the title Why missing required factory parameter is replaced with null? Why missing required factory parameter is silently replaced with null? Dec 8, 2020
@escamoteur
Copy link
Collaborator

This looks to me as if you are using injectable. I think get_it doesn't do anything like that.

@AlexanderFarkas
Copy link
Author

AlexanderFarkas commented Dec 8, 2020

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

@escamoteur
Copy link
Collaborator

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()´

@AlexanderFarkas
Copy link
Author

AlexanderFarkas commented Dec 9, 2020

I suppose, it should at least throw, when required param is not passed. And, of course, it shouldn't be null by default

@escamoteur
Copy link
Collaborator

could you creat a PR with a unit test for this?

@escamoteur escamoteur added bug Something isn't working enhancement New feature or request labels Jan 28, 2021
@sannykhan3777
Copy link

@escamoteur Any solutions to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants