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

The reactive form model class cannot have a constructor with non-nullable fields #69

Closed
efraimbart opened this issue Jan 18, 2023 · 14 comments

Comments

@efraimbart
Copy link

When the generated code constructs the model class it uses null propagation to get the corresponding property from the original model instance, thereby attempting to pass in a nullable version of the expected property type.

An example of where this issue can be seen is in login_extended. It's only not an issue in this instance because LoginExtended.unAnnotated is nullable, but if it's changed to non-nullable it would cause a compile time error.

The one example I've seen where it set the model as nullable, and therefore doesn't require null propagation when accessing it's properties, is in profile, but I don't know how to replicate.

@vasilich6107
Copy link
Contributor

but if it's changed to non-nullable it would cause a compile time error.

Hi. If it will change to non nullable - you have to regenerate the code.

May be you can provide more details about your issue

@efraimbart
Copy link
Author

efraimbart commented Jan 23, 2023

I've regenerated the code with the property as a non-nullable and it continued to treat it as nullable. That's essentially the issue I'm reporting.

I've made some more changes and it's no longer doing that, but I'm not sure what caused it. Perhaps adding an id property to the model?

I now have another similar issue where it's trying to pass the id property into the constructor as a named argument despite the constructor requiring it as a positional arguments, causing compile time errors.

@efraimbart
Copy link
Author

@vasilich6107 I've forked the repo and created two branches with updated examples to show the above issues.

  1. Nullable values passed into non-nullable parameters.
  2. Named arguments used when positional arguments expected.

If you need any more clarification just let me know, thanks!

@efraimbart
Copy link
Author

@vasilich6107 Any thoughts on the above?

@vasilich6107
Copy link
Contributor

HI @efraimbart
I took first example

image

It generates slightly different code
image

Login model becomes required no as far as it has non nullable required values to pass through
image

@vasilich6107
Copy link
Contributor

case 2 fixed in reactive_forms_generator 0.23.3

@efraimbart
Copy link
Author

HI @efraimbart I took first example

image

It generates slightly different code image

Login model becomes required no as far as it has non nullable required values to pass through image

The difference between my generated code and your generated code is probably because in the model I put required this.nonNullable = '' while you put required this.nonNullable. Perhaps the default value causes the generator to treat the parameter as nullable, but that doesn't work in dart (see dart-lang/language#219).

@efraimbart
Copy link
Author

case 2 fixed in reactive_forms_generator 0.23.3

Great, will try this in a bit.

@vasilich6107
Copy link
Contributor

@efraimbart could you clarify if the issue is fixed

@efraimbart
Copy link
Author

I'm in the midst of a refactor so I haven't had a chance to try it yet, but I'll try to get to it very soon.

@efraimbart
Copy link
Author

efraimbart commented Feb 3, 2023

Issue 2 seems resolved, but issue 1 still seems to be active.

@vasilich6107
Copy link
Contributor

Hi @efraimbart
The issue in the model definition
image

@vasilich6107
Copy link
Contributor

Fix your model and you'll get the proper result
image

@vasilich6107
Copy link
Contributor

Closing the issue as far as we fixed one thing and identified the fix for another one.

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