Skip to content

registerFactoryParam does not allow subclasses for param types? #62

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
nlfiedler opened this issue Apr 4, 2020 · 12 comments
Closed

registerFactoryParam does not allow subclasses for param types? #62

nlfiedler opened this issue Apr 4, 2020 · 12 comments

Comments

@nlfiedler
Copy link

It looks like registerFactoryParam() does not allow invocation of the factory function in which one of the parameters is an object that is a subclass of the defined parameter type. Is my understanding correct, and is this expected behavior? Should I be using some other method instead?

For instance, I register my factory like so:

  getIt.registerFactoryParam<PackStoreDetails, PackStore, void>(
    (param1, param2) => buildStoreDetails(param1, param2),
  );

PackStore is a simple class that is extended by PackStoreModel, and an instance of the latter is passed to the factory method, at which point I get this error:

Assertion failed:
file:///Users/nfiedler/flutter/.pub-cache/hosted/pub.dartlang.org/get_it-4.0.1/lib/get_it_impl.dart:108:17
param1 == null || param1.runtimeType == param1Type
"Incompatible Type passed as param1\nexpected: PackStore actual: PackStoreModel"

Thanks

@jacovdbosch
Copy link

Got the same issue while using https://pub.dev/packages/freezed.

@escamoteur
Copy link
Collaborator

I probably should use is instead ==. I will try if that helps

@nlangh
Copy link

nlangh commented Apr 20, 2020

Same with https://pub.dev/packages/built_value:

Failed assertion: 
line 108 pos 17: 'param1 == null || param1.runtimeType == param1Type': 
Incompatible Type passed as param1
E/flutter ( 2589): expected: Profile actual: _$Profile

param1 == null || param1 is P1 seems to work fine

@damascenaluiz
Copy link

I have the same problem, maybe the suggestion above should be included in a next version

@votruk
Copy link

votruk commented Apr 22, 2020

@escamoteur replacing == with is works as I describe in #67

@escamoteur
Copy link
Collaborator

@votruk I tried it and it didn't work because is does not work between a runtime type and a variable of type Type.

if it works for you I really would like to know how.

@escamoteur
Copy link
Collaborator

Next version has this test removed because of limitation of Dart

@bDev10
Copy link

bDev10 commented Jan 12, 2021

@escamoteur It looks like for asynchronous factories this issue still exists in newest 5.0.4 version. I got it when using registerFactoryParamAsync.

@escamoteur escamoteur reopened this Jan 12, 2021
@escamoteur
Copy link
Collaborator

could you add a small test in a PR?

@escamoteur
Copy link
Collaborator

Sorry for the late reply

@escamoteur
Copy link
Collaborator

Forget it, I found the problem

@escamoteur
Copy link
Collaborator

Fixed in V5.0.6

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

7 participants